Freeze SCUM SQLite template run contract

This commit is contained in:
npc0-hue
2026-08-13 13:05:39 +08:00
parent 36ed8822c3
commit 467d5c3a8c
17 changed files with 683 additions and 12 deletions
+103
View File
@@ -59,6 +59,19 @@ const (
SCUMSafeErrorCancelled SCUMSafeErrorCode = "cancelled"
SCUMSafeErrorSourceChanged SCUMSafeErrorCode = "source_changed"
SCUMSafeErrorResultLimitExceeded SCUMSafeErrorCode = "result_limit_exceeded"
SCUMSafeErrorTemplateMissing SCUMSafeErrorCode = "template_missing"
SCUMSafeErrorTemplateMismatch SCUMSafeErrorCode = "template_digest_mismatch"
SCUMSafeErrorParameterInvalid SCUMSafeErrorCode = "parameter_schema_invalid"
SCUMSafeErrorRowLimitExceeded SCUMSafeErrorCode = "row_limit_exceeded"
SCUMSafeErrorResultSchemaInvalid SCUMSafeErrorCode = "result_schema_invalid"
)
type SCUMTerminalResultStatus string
const (
SCUMTerminalResultSucceeded SCUMTerminalResultStatus = "succeeded"
SCUMTerminalResultFailed SCUMTerminalResultStatus = "failed"
SCUMTerminalResultCancelled SCUMTerminalResultStatus = "cancelled"
)
type SCUMSafeError struct {
@@ -93,6 +106,18 @@ func DefaultSCUMSchemaProbeBounds() SCUMSchemaProbeBounds {
return SCUMSchemaProbeBounds{MaxObjects: 256, MaxColumnsPerObject: 128, MaxIndexesPerObject: 64, MaxForeignKeys: 64, MaxCardinalityReads: 64, MaxSampleRows: 3, TimeoutMS: 5000, MaxResultBytes: 512 * 1024}
}
type SCUMSQLiteTemplateBounds struct {
MaxParameters int
MaxRows int
TimeoutMS int
BusyTimeoutMS int
MaxResultBytes int
}
func DefaultSCUMSQLiteTemplateBounds() SCUMSQLiteTemplateBounds {
return SCUMSQLiteTemplateBounds{MaxParameters: 64, MaxRows: 500, TimeoutMS: 5000, BusyTimeoutMS: 250, MaxResultBytes: 1024 * 1024}
}
type SCUMSchemaProbeRequest struct {
RequestID string
JobID string
@@ -101,6 +126,22 @@ type SCUMSchemaProbeRequest struct {
RequestedAt time.Time
}
type SCUMSQLiteTemplateRequest struct {
RequestID string
JobID string
Binding SCUMBindingIdentity
Capability SCUMDataCapability
TargetKey string
TemplateKey string
AdapterVersion string
RequiredSchemaFingerprint string
AssetDigest string
ParameterDigest string
Parameters map[string]any
Bounds SCUMSQLiteTemplateBounds
RequestedAt time.Time
}
type SCUMSchemaProbeDeclaration struct {
Capability string
TargetKey string
@@ -168,6 +209,28 @@ type SCUMSchemaProbeResult struct {
Limits SCUMSchemaProbeBounds
}
type SCUMSQLiteTemplateResult struct {
RequestID string
JobID string
Binding SCUMBindingIdentity
Status SCUMTerminalResultStatus
Capability SCUMDataCapability
TargetKey string
TemplateKey string
AdapterVersion string
SchemaFingerprint string
AssetDigest string
ParameterDigest string
SourceFingerprint string
ObservedAt time.Time
ResultDigest string
RowCount int
Rows []map[string]any
Truncated bool
SafeError SCUMSafeError
Limits SCUMSQLiteTemplateBounds
}
type SCUMCapabilityRequirement struct {
Capability SCUMDataCapability
AdapterVersion string
@@ -260,6 +323,46 @@ func CopySCUMCapabilityEvidence(value SCUMCapabilityEvidence) SCUMCapabilityEvid
return value
}
func CopySCUMSQLiteTemplateRequestPtr(value *SCUMSQLiteTemplateRequest) *SCUMSQLiteTemplateRequest {
if value == nil {
return nil
}
copy := *value
copy.Parameters = CopySCUMValueMap(value.Parameters)
return &copy
}
func CopySCUMSQLiteTemplateResultPtr(value *SCUMSQLiteTemplateResult) *SCUMSQLiteTemplateResult {
if value == nil {
return nil
}
copy := *value
copy.Rows = CopySCUMRows(value.Rows)
return &copy
}
func CopySCUMValueMap(value map[string]any) map[string]any {
if value == nil {
return nil
}
copy := make(map[string]any, len(value))
for key, item := range value {
copy[key] = item
}
return copy
}
func CopySCUMRows(rows []map[string]any) []map[string]any {
if rows == nil {
return nil
}
copy := make([]map[string]any, len(rows))
for index, row := range rows {
copy[index] = CopySCUMValueMap(row)
}
return copy
}
func CopySCUMSchemaProbeResult(value SCUMSchemaProbeResult) SCUMSchemaProbeResult {
value.Objects = append([]SCUMSchemaObjectEvidence(nil), value.Objects...)
for index := range value.Objects {