memeloop 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/dist/browser.cjs +1413 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +3066 -0
- package/dist/browser.d.ts +3066 -0
- package/dist/browser.js +43 -0
- package/dist/chunk-2C6BJZI3.js +382 -0
- package/dist/chunk-2C6BJZI3.js.map +1 -0
- package/dist/chunk-426CJUZP.js +630 -0
- package/dist/chunk-426CJUZP.js.map +1 -0
- package/dist/chunk-7ZDTB4VZ.js +63 -0
- package/dist/chunk-7ZDTB4VZ.js.map +1 -0
- package/dist/chunk-AZFYDWIN.js +98 -0
- package/dist/chunk-AZFYDWIN.js.map +1 -0
- package/dist/chunk-BGPU4RR7.js +367 -0
- package/dist/chunk-BGPU4RR7.js.map +1 -0
- package/dist/chunk-CCEFAOSH.js +496 -0
- package/dist/chunk-CCEFAOSH.js.map +1 -0
- package/dist/chunk-FWSY5HOA.js +63 -0
- package/dist/chunk-FWSY5HOA.js.map +1 -0
- package/dist/chunk-GYIOMQMY.js +8726 -0
- package/dist/chunk-GYIOMQMY.js.map +1 -0
- package/dist/chunk-K6P63KD4.js +68 -0
- package/dist/chunk-K6P63KD4.js.map +1 -0
- package/dist/chunk-KFS2EJT6.js +42 -0
- package/dist/chunk-KFS2EJT6.js.map +1 -0
- package/dist/chunk-MAJWHAKR.js +3637 -0
- package/dist/chunk-MAJWHAKR.js.map +1 -0
- package/dist/chunk-MRKY4HGF.js +205 -0
- package/dist/chunk-MRKY4HGF.js.map +1 -0
- package/dist/chunk-T7FSXWFR.js +2744 -0
- package/dist/chunk-T7FSXWFR.js.map +1 -0
- package/dist/chunk-VZKQX5PP.js +1 -0
- package/dist/chunk-VZKQX5PP.js.map +1 -0
- package/dist/chunk-WAI6BODI.js +175 -0
- package/dist/chunk-WAI6BODI.js.map +1 -0
- package/dist/chunk-YMNXDNDW.js +798 -0
- package/dist/chunk-YMNXDNDW.js.map +1 -0
- package/dist/conversation.cjs +208 -0
- package/dist/conversation.cjs.map +1 -0
- package/dist/conversation.d.cts +100 -0
- package/dist/conversation.d.ts +100 -0
- package/dist/conversation.js +21 -0
- package/dist/conversation.js.map +1 -0
- package/dist/device-network-portable.cjs +702 -0
- package/dist/device-network-portable.cjs.map +1 -0
- package/dist/device-network-portable.d.cts +110 -0
- package/dist/device-network-portable.d.ts +110 -0
- package/dist/device-network-portable.js +53 -0
- package/dist/device-network-portable.js.map +1 -0
- package/dist/device-network.cjs +906 -0
- package/dist/device-network.cjs.map +1 -0
- package/dist/device-network.d.cts +6 -0
- package/dist/device-network.d.ts +6 -0
- package/dist/device-network.js +59 -0
- package/dist/device-network.js.map +1 -0
- package/dist/fetchProvider-WWnWnQFP.d.ts +91 -0
- package/dist/fetchProvider-toTHy5Nu.d.cts +91 -0
- package/dist/index.cjs +28051 -5459
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -1320
- package/dist/index.d.ts +94 -1320
- package/dist/index.js +10616 -2420
- package/dist/index.js.map +1 -1
- package/dist/interface-IrKBFtL1.d.cts +493 -0
- package/dist/interface-IrKBFtL1.d.ts +493 -0
- package/dist/llm-providers.cjs +43 -8
- package/dist/llm-providers.cjs.map +1 -1
- package/dist/llm-providers.d.cts +2 -1
- package/dist/llm-providers.d.ts +2 -1
- package/dist/llm-providers.js +4 -2
- package/dist/llm-providers.js.map +1 -1
- package/dist/loop-api.cjs +5227 -2010
- package/dist/loop-api.cjs.map +1 -1
- package/dist/loop-api.d.cts +11 -5
- package/dist/loop-api.d.ts +11 -5
- package/dist/loop-api.js +86 -49
- package/dist/mobile.cjs +2711 -0
- package/dist/mobile.cjs.map +1 -0
- package/dist/mobile.d.cts +6 -0
- package/dist/mobile.d.ts +6 -0
- package/dist/mobile.js +22 -0
- package/dist/mobile.js.map +1 -0
- package/dist/orchestration-portable-BHB_YrNN.d.ts +2192 -0
- package/dist/orchestration-portable-mvYBvGBb.d.cts +2192 -0
- package/dist/orchestration-portable.cjs +9553 -0
- package/dist/orchestration-portable.cjs.map +1 -0
- package/dist/orchestration-portable.d.cts +5 -0
- package/dist/orchestration-portable.d.ts +5 -0
- package/dist/orchestration-portable.js +290 -0
- package/dist/orchestration-portable.js.map +1 -0
- package/dist/pairingInvite-BXPWY3aM.d.cts +149 -0
- package/dist/pairingInvite-Cuz0wuq9.d.ts +149 -0
- package/dist/promptConcat-0WNFTg4l.d.ts +516 -0
- package/dist/promptConcat-D6wr5V-V.d.cts +516 -0
- package/dist/providerRegistry-Bi6pAvSj.d.ts +86 -0
- package/dist/providerRegistry-CPsktuiX.d.cts +86 -0
- package/dist/registry-D0kbxksn.d.cts +393 -0
- package/dist/registry-DDbvhlhs.d.ts +393 -0
- package/dist/remoteClient-B_spK019.d.ts +87 -0
- package/dist/remoteClient-CBggnRy3.d.cts +87 -0
- package/dist/runtime-PGWR6FIV.js +18 -0
- package/dist/runtime-PGWR6FIV.js.map +1 -0
- package/dist/scriptDeploymentPipeline-CXJcC82H.d.ts +2464 -0
- package/dist/scriptDeploymentPipeline-yG1ZhVVI.d.cts +2464 -0
- package/dist/syncCloudDevices-BEqwgrhD.d.ts +49 -0
- package/dist/syncCloudDevices-Ds_Kcgrv.d.cts +49 -0
- package/dist/types-7pYti-k9.d.cts +255 -0
- package/dist/types-CdFVSntj.d.ts +255 -0
- package/package.json +110 -35
- package/dist/anthropic.cjs +0 -72
- package/dist/anthropic.cjs.map +0 -1
- package/dist/anthropic.d.cts +0 -21
- package/dist/anthropic.d.ts +0 -21
- package/dist/anthropic.js +0 -21
- package/dist/anthropic.js.map +0 -1
- package/dist/azure.cjs +0 -72
- package/dist/azure.cjs.map +0 -1
- package/dist/azure.d.cts +0 -21
- package/dist/azure.d.ts +0 -21
- package/dist/azure.js +0 -21
- package/dist/azure.js.map +0 -1
- package/dist/chunk-3CN7DFBL.js +0 -4894
- package/dist/chunk-3CN7DFBL.js.map +0 -1
- package/dist/chunk-4AZ4D7U5.js +0 -32
- package/dist/chunk-4AZ4D7U5.js.map +0 -1
- package/dist/chunk-6ON4XSOV.js +0 -63
- package/dist/chunk-6ON4XSOV.js.map +0 -1
- package/dist/chunk-DJQNGIXX.js +0 -4793
- package/dist/chunk-DJQNGIXX.js.map +0 -1
- package/dist/chunk-FKQP6AOQ.js +0 -32
- package/dist/chunk-FKQP6AOQ.js.map +0 -1
- package/dist/chunk-OVJ7JJBA.js +0 -35
- package/dist/chunk-OVJ7JJBA.js.map +0 -1
- package/dist/chunk-P4UZ7IXC.js +0 -42
- package/dist/chunk-YHJ2AEFR.js +0 -4933
- package/dist/chunk-YHJ2AEFR.js.map +0 -1
- package/dist/chunk-YVK7RYRO.js +0 -4973
- package/dist/chunk-YVK7RYRO.js.map +0 -1
- package/dist/code-assistant.json +0 -114
- package/dist/cohere.cjs +0 -72
- package/dist/cohere.cjs.map +0 -1
- package/dist/cohere.d.cts +0 -21
- package/dist/cohere.d.ts +0 -21
- package/dist/cohere.js +0 -21
- package/dist/cohere.js.map +0 -1
- package/dist/deepseek.cjs +0 -72
- package/dist/deepseek.cjs.map +0 -1
- package/dist/deepseek.d.cts +0 -21
- package/dist/deepseek.d.ts +0 -21
- package/dist/deepseek.js +0 -21
- package/dist/deepseek.js.map +0 -1
- package/dist/dist-65U7OYRG.js +0 -1257
- package/dist/dist-65U7OYRG.js.map +0 -1
- package/dist/fetchProvider-Cu4WkU5O.d.cts +0 -819
- package/dist/fetchProvider-Cu4WkU5O.d.ts +0 -819
- package/dist/frontend-ui-ux.json +0 -105
- package/dist/general-assistant.json +0 -95
- package/dist/git-master.json +0 -51
- package/dist/google-vertex.cjs +0 -72
- package/dist/google-vertex.cjs.map +0 -1
- package/dist/google-vertex.d.cts +0 -21
- package/dist/google-vertex.d.ts +0 -21
- package/dist/google-vertex.js +0 -21
- package/dist/google-vertex.js.map +0 -1
- package/dist/google.cjs +0 -72
- package/dist/google.cjs.map +0 -1
- package/dist/google.d.cts +0 -21
- package/dist/google.d.ts +0 -21
- package/dist/google.js +0 -21
- package/dist/google.js.map +0 -1
- package/dist/groq.cjs +0 -72
- package/dist/groq.cjs.map +0 -1
- package/dist/groq.d.cts +0 -21
- package/dist/groq.d.ts +0 -21
- package/dist/groq.js +0 -21
- package/dist/groq.js.map +0 -1
- package/dist/index.d.mts +0 -3203
- package/dist/index.mjs +0 -7064
- package/dist/index.mjs.map +0 -1
- package/dist/mistral.cjs +0 -72
- package/dist/mistral.cjs.map +0 -1
- package/dist/mistral.d.cts +0 -21
- package/dist/mistral.d.ts +0 -21
- package/dist/mistral.js +0 -21
- package/dist/mistral.js.map +0 -1
- package/dist/multipart-parser-EJCXIUHC.js +0 -372
- package/dist/multipart-parser-EJCXIUHC.js.map +0 -1
- package/dist/openai.cjs +0 -72
- package/dist/openai.cjs.map +0 -1
- package/dist/openai.d.cts +0 -21
- package/dist/openai.d.ts +0 -21
- package/dist/openai.js +0 -21
- package/dist/openai.js.map +0 -1
- package/dist/perplexity.cjs +0 -72
- package/dist/perplexity.cjs.map +0 -1
- package/dist/perplexity.d.cts +0 -21
- package/dist/perplexity.d.ts +0 -21
- package/dist/perplexity.js +0 -21
- package/dist/perplexity.js.map +0 -1
- package/dist/playwright.json +0 -52
- package/dist/promptConcat-BJdazTg5.d.cts +0 -1832
- package/dist/promptConcat-BJdazTg5.d.ts +0 -1832
- package/dist/promptConcat-CAkpni_8.d.cts +0 -1834
- package/dist/promptConcat-CAkpni_8.d.ts +0 -1834
- package/dist/promptConcat-CfH5-GAE.d.cts +0 -1036
- package/dist/promptConcat-ChcAZOOL.d.ts +0 -1036
- package/dist/promptConcat-G5TnJVRy.d.cts +0 -1800
- package/dist/promptConcat-G5TnJVRy.d.ts +0 -1800
- package/dist/promptConcat-L72eowzp.d.ts +0 -1090
- package/dist/promptConcat-eLHdN7K8.d.cts +0 -1090
- package/dist/src-VTSXKG72.js +0 -1409
- package/dist/src-VTSXKG72.js.map +0 -1
- package/dist/togetherai.cjs +0 -72
- package/dist/togetherai.cjs.map +0 -1
- package/dist/togetherai.d.cts +0 -21
- package/dist/togetherai.d.ts +0 -21
- package/dist/togetherai.js +0 -21
- package/dist/togetherai.js.map +0 -1
- package/dist/types-B0Jm2l38.d.cts +0 -767
- package/dist/types-B0Jm2l38.d.ts +0 -767
- package/dist/xai.cjs +0 -72
- package/dist/xai.cjs.map +0 -1
- package/dist/xai.d.cts +0 -21
- package/dist/xai.d.ts +0 -21
- package/dist/xai.js +0 -21
- package/dist/xai.js.map +0 -1
- /package/dist/{chunk-P4UZ7IXC.js.map → browser.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/orchestration/resources.ts"],"sourcesContent":["import type { OrchestrationObjectMetadata, OrchestrationOwnerReference, OrchestrationResourceManifest, OrchestrationResourceStatus, OrchestrationTypeMeta } from './client.js';\nimport type { OrchestrationErrorData } from './errors.js';\n\nexport const AGENT_WORKLOAD_API_VERSION = 'workload.memeloop.io/v1alpha1';\nexport const AGENT_WORKLOAD_KIND = 'AgentWorkload';\n\nexport const AGENT_RUN_API_VERSION = 'run.memeloop.io/v1alpha1';\nexport const AGENT_RUN_KIND = 'AgentRun';\n\n/**\n * Host-asserted trust classification of a node or workload. The trust class\n * is bound by the host; it is never self-reported by the workload, the model,\n * or a `.mjs` script.\n */\nexport type NodeTrustClass = 'trusted' | 'restricted' | 'quarantine';\n\nexport type AgentTrustLevel = NodeTrustClass;\n\n/** Ordered data classifications; higher ranks are more sensitive. */\nexport type DataClassification = 'public' | 'internal' | 'confidential' | 'restricted';\n\nexport type ToolAdmissionAction = 'allow' | 'deny' | 'require-approval';\n\n/**\n * Declarative trusted-admission rule. Rules are evaluated in order; the first\n * matching rule wins (firewall semantics). A rule matches when `toolPattern`\n * matches the tool reference name and either `effects` is omitted (all\n * effects) or contains the operation effect.\n */\nexport interface ToolAdmissionRule {\n toolPattern: string;\n effects?: ToolOperationEffect[];\n action: ToolAdmissionAction;\n reason?: string;\n}\n\nexport interface ToolAdmissionPolicy {\n /** Applied when no rule matches. Restricted/quarantine profiles resolve to `deny` regardless of this field. */\n defaultAction: ToolAdmissionAction;\n rules?: ToolAdmissionRule[];\n}\n\nexport interface AgentWorkloadModelPolicy {\n modelClass?: string;\n allowedModelNames?: string[];\n budget?: {\n maxTokens?: number;\n maxCost?: number;\n };\n}\n\nexport interface AgentWorkloadToolPolicy {\n allowedToolClasses?: string[];\n /** Tool classes that must have a healthy executor on the selected node. */\n requiredToolClasses?: string[];\n allowedToolIds?: string[];\n defaultAction?: 'allow' | 'ask' | 'deny';\n rules?: Array<{ pattern: string; action: 'allow' | 'ask' | 'deny' }>;\n}\n\nexport interface AgentWorkloadNetworkPolicy {\n networkClass?: string;\n egress?: 'none' | 'same-node' | 'restricted' | 'open';\n /** Minimum boundary that must enforce this policy before the workload binds. */\n minimumEnforcement?: 'none' | 'process' | 'namespace' | 'host' | 'external';\n}\n\nexport interface AgentWorkloadVolumeClaim {\n name: string;\n claimRef: string;\n}\n\nexport interface AgentWorkloadStoragePolicy {\n storageClass?: string;\n volumes?: AgentWorkloadVolumeClaim[];\n}\n\nexport interface AgentWorkloadCredentialPolicy {\n /** Credential broker class required on the selected node. */\n brokerClass?: string;\n /** Audiences for which the node must be able to request scoped grants. */\n audiences?: string[];\n /** Target classes for which scoped grants may be issued. */\n targets?: string[];\n}\n\nexport interface AgentWorkloadResourceRequirements {\n cpuMillicores?: number;\n memoryBytes?: number;\n gpuCount?: number;\n diskBytes?: number;\n bandwidthKbps?: number;\n}\n\nexport interface AgentWorkloadPlacement {\n /**\n * Registered external-orchestrator driver name. When set, the external\n * orchestration controller owns placement and the local node binder skips\n * this workload. External placement is always explicit; there is no silent\n * spillover from the local runtime.\n */\n orchestrator?: string;\n nodeSelector?: Record<string, string>;\n requiredNode?: string;\n antiAffinity?: string[];\n /** Soft co-location preference; never overrides a hard security filter. */\n preferredNode?: string;\n /** Taints the workload tolerates. Nodes with taints not listed here are filtered out. */\n tolerations?: string[];\n /**\n * Maximum data classification the workload may carry. Nodes with a lower\n * `maxDataClassification` than the workload's effective classification are\n * filtered out. Quarantine nodes are always treated as `public`-only.\n */\n dataClassification?: DataClassification;\n /** Allowed residency labels (for example `local`, `cn`, or `eu-west`). */\n dataResidency?: string[];\n /** Require a currently verified node attestation. */\n requireAttestation?: boolean;\n /** Fleet batch constraints enforced before a target binds. */\n rollout?: {\n batchId: string;\n excludedFaultDomains?: string[];\n maxConcurrentPerFaultDomain?: number;\n };\n}\n\nexport type AgentWorkloadCompletionPolicy = 'complete' | 'detach' | 'daemon';\n\nexport interface AgentWorkloadSpec {\n profileId?: string;\n scriptReference?: string;\n promptReference?: string;\n trust?: AgentTrustLevel;\n /** RuntimeClass selected for script workloads (plan 24.18); declarative only. */\n runtimeClass?: string;\n /**\n * Non-secret environment variables for the workload (plan 24.14 `env`).\n * Secret-shaped values are rejected at admission (deployGeneratedScript)\n * and stripped again at launch (plan 24.35), so specs persisted in the\n * ControlStore never carry provider keys.\n */\n env?: Record<string, string>;\n /** Name of a SecurityProfile resource governing admission and model access. */\n securityProfileRef?: string;\n placement?: AgentWorkloadPlacement;\n modelPolicy?: AgentWorkloadModelPolicy;\n toolPolicy?: AgentWorkloadToolPolicy;\n networkPolicy?: AgentWorkloadNetworkPolicy;\n storagePolicy?: AgentWorkloadStoragePolicy;\n credentialPolicy?: AgentWorkloadCredentialPolicy;\n resources?: AgentWorkloadResourceRequirements;\n /** Content-addressed artifacts whose locality may influence placement. */\n artifactReferences?: string[];\n /** Durable checkpoint whose locality may influence placement. */\n checkpointReference?: string;\n completionPolicy?: AgentWorkloadCompletionPolicy;\n ownerReferences?: OrchestrationOwnerReference[];\n}\n\nexport interface AgentWorkloadStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Scheduling' | 'Running' | 'Completed' | 'Failed';\n /** Node the binding controller scheduled this workload onto. */\n assignedNode?: string;\n /** Durable trusted policy decision that authorized the current binding. */\n placementDecisionRef?: string;\n /** Policy snapshot digest bound to placementDecisionRef. */\n placementPolicyDigest?: string;\n /** External driver selected for this workload, when any. */\n assignedDriver?: string;\n /** Opaque native workload identifier returned by the external driver. */\n externalId?: string;\n /** Non-secret, string-only backend metadata used for diagnostics/adoption. */\n externalMetadata?: Record<string, string>;\n runs?: Array<{\n apiVersion: string;\n kind: string;\n name?: string;\n namespace?: string;\n uid?: string;\n }>;\n lastRunResult?: string;\n}\n\nexport interface AgentWorkloadCondition {\n type: string;\n status: 'True' | 'False' | 'Unknown';\n}\n\nexport type AgentWorkloadManifest = OrchestrationResourceManifest<AgentWorkloadSpec>;\n\nexport interface AgentWorkloadResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: AgentWorkloadSpec;\n status?: AgentWorkloadStatus;\n}\n\nexport interface AgentRunSpec {\n workloadRef: {\n apiVersion: string;\n kind: string;\n name?: string;\n namespace?: string;\n uid?: string;\n };\n promptReference?: string;\n retry?: number;\n timeoutMs?: number;\n}\n\nexport interface AgentRunStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Starting' | 'Running' | 'Completed' | 'Failed' | 'Cancelled';\n /**\n * Durable claim written before invoking a LoopRuntimeDriver. A different\n * daemon instance that observes Starting/Running must adopt through a\n * managed driver or fail UNKNOWN_EFFECT; it must never blindly start again.\n */\n runtimeExecutionClaim?: {\n controllerInstanceId: string;\n claimedAt: string;\n };\n /** Independently selected serving endpoint for this run's model calls. */\n assignedModelEndpoint?: {\n apiVersion: string;\n kind: string;\n name: string;\n namespace?: string;\n uid: string;\n };\n /** Fences the model binding decision to the controller leadership epoch. */\n modelBinding?: {\n leaseEpoch: string;\n endpointResourceVersion: string;\n boundAt: string;\n };\n /** NetworkAttachment that must reach Attached before this run starts. */\n networkAttachmentRef?: {\n apiVersion: string;\n kind: string;\n name: string;\n namespace?: string;\n uid: string;\n };\n volumePhase?: 'Pending' | 'Publishing' | 'Ready' | 'Releasing' | 'Released' | 'Failed';\n volumePublishClaim?: {\n leaseEpoch: string;\n claimedAt: string;\n };\n volumeBindings?: Array<{\n name: string;\n claimRef: { name: string; uid: string };\n volumeRef: { name: string; uid: string };\n assignedDriver: string;\n assignedNode: string;\n /** Managed node-stage handle used for ordered publish cleanup. */\n stageHandle?: string;\n publishHandle: string;\n readOnly: boolean;\n }>;\n volumeReleaseRequestedAt?: string;\n volumeError?: OrchestrationErrorData;\n outputReference?: string;\n summary?: string;\n exitCode?: number;\n}\n\nexport interface AgentRunCondition {\n type: string;\n status: 'True' | 'False' | 'Unknown';\n}\n\nexport type AgentRunManifest = OrchestrationResourceManifest<AgentRunSpec>;\n\nexport interface AgentRunResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: AgentRunSpec;\n status?: AgentRunStatus;\n}\n\nexport function createAgentWorkloadManifest(name: string, spec: AgentWorkloadSpec): AgentWorkloadManifest {\n return {\n apiVersion: AGENT_WORKLOAD_API_VERSION,\n kind: AGENT_WORKLOAD_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function createAgentRunManifest(name: string, spec: AgentRunSpec): AgentRunManifest {\n return {\n apiVersion: AGENT_RUN_API_VERSION,\n kind: AGENT_RUN_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isAgentWorkload(resource: { apiVersion?: string; kind?: string }): resource is AgentWorkloadResource {\n return resource.apiVersion === AGENT_WORKLOAD_API_VERSION && resource.kind === AGENT_WORKLOAD_KIND;\n}\n\nexport function isAgentRun(resource: { apiVersion?: string; kind?: string }): resource is AgentRunResource {\n return resource.apiVersion === AGENT_RUN_API_VERSION && resource.kind === AGENT_RUN_KIND;\n}\n\nexport function agentWorkloadReference(name: string, namespace?: string): {\n apiVersion: string;\n kind: string;\n name: string;\n namespace?: string;\n} {\n return {\n apiVersion: AGENT_WORKLOAD_API_VERSION,\n kind: AGENT_WORKLOAD_KIND,\n name,\n namespace,\n };\n}\n\nexport const TOOL_OPERATION_API_VERSION = 'execution.memeloop.io/v1alpha1';\nexport const TOOL_OPERATION_KIND = 'ToolOperation';\n\nexport type ToolOperationEffect = 'read' | 'create' | 'update' | 'delete' | 'execute' | 'unknown';\n\nexport interface ToolOperationToolReference {\n apiVersion?: string;\n kind: string;\n name: string;\n namespace?: string;\n /** Expected input/output schema digest; executors with another digest are rejected. */\n schemaDigest?: string;\n}\n\nexport interface ToolOperationRetryPolicy {\n maxAttempts?: number;\n nonRetryable?: boolean;\n fencingToken?: string;\n}\n\nexport interface ToolOperationPolicy {\n requireApproval?: boolean;\n auditLevel?: 'none' | 'metadata' | 'payload';\n}\n\nexport interface ToolOperationSpec {\n toolRef: ToolOperationToolReference;\n arguments?: Record<string, unknown>;\n effect: ToolOperationEffect;\n idempotencyKey?: string;\n timeoutMs?: number;\n retry?: ToolOperationRetryPolicy;\n policy?: ToolOperationPolicy;\n /** Explicit registered external-orchestrator driver selection. */\n placement?: {\n orchestrator?: string;\n requiredNode?: string;\n preferredNode?: string;\n nodeSelector?: Record<string, string>;\n minimumTrust?: NodeTrustClass;\n };\n}\n\nexport interface ToolOperationResult {\n value?: unknown;\n error?: OrchestrationErrorData;\n evidenceRef?: string;\n}\n\nexport interface ToolOperationApprovalEvidence {\n approvalId: string;\n decision: 'allow' | 'deny';\n /** Trusted human/service identity. Model-provided identities are invalid. */\n actor: string;\n decidedAt: string;\n reason?: string;\n}\n\nexport interface ToolOperationStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Running' | 'Completed' | 'Failed' | 'Cancelled';\n result?: ToolOperationResult;\n attempts?: number;\n startedAt?: string;\n completedAt?: string;\n /** Trusted approval evidence returned by the host-bound approval driver. */\n approval?: ToolOperationApprovalEvidence;\n assignedDriver?: string;\n assignedNode?: string;\n assignedExecutor?: {\n apiVersion: string;\n kind: string;\n name: string;\n namespace?: string;\n uid?: string;\n };\n /**\n * Durable claim written before a local effect starts. A different fencing\n * epoch observing Running must reconcile unknown effect instead of blindly\n * repeating the operation.\n */\n executionClaim?: {\n leaseEpoch: string;\n claimedAt: string;\n };\n externalId?: string;\n externalMetadata?: Record<string, string>;\n}\n\nexport type ToolOperationManifest = OrchestrationResourceManifest<ToolOperationSpec>;\n\nexport interface ToolOperationResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: ToolOperationSpec;\n status?: ToolOperationStatus;\n}\n\nexport function createToolOperationManifest(name: string, spec: ToolOperationSpec): ToolOperationManifest {\n return {\n apiVersion: TOOL_OPERATION_API_VERSION,\n kind: TOOL_OPERATION_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isToolOperation(resource: { apiVersion?: string; kind?: string }): resource is ToolOperationResource {\n return resource.apiVersion === TOOL_OPERATION_API_VERSION && resource.kind === TOOL_OPERATION_KIND;\n}\n\nexport function agentRunReference(name: string, namespace?: string): {\n apiVersion: string;\n kind: string;\n name: string;\n namespace?: string;\n} {\n return {\n apiVersion: AGENT_RUN_API_VERSION,\n kind: AGENT_RUN_KIND,\n name,\n namespace,\n };\n}\n\nexport const TOOL_CLASS_API_VERSION = 'tool.memeloop.io/v1alpha1';\nexport const TOOL_CLASS_KIND = 'ToolClass';\n\nexport const TOOL_EXECUTOR_API_VERSION = 'tool.memeloop.io/v1alpha1';\nexport const TOOL_EXECUTOR_KIND = 'ToolExecutor';\n\nexport type ToolRiskLevel = 'none' | 'low' | 'medium' | 'high' | 'critical';\n\nexport interface ToolClassSchema {\n input: Record<string, unknown>;\n output?: Record<string, unknown>;\n required?: string[];\n}\n\nexport interface ToolClassSpec {\n description?: string;\n version?: string;\n schema: ToolClassSchema;\n schemaDigest?: string;\n risk?: ToolRiskLevel;\n effects?: ToolOperationEffect[];\n allowedTargets?: string[];\n categories?: string[];\n}\n\nexport interface ToolClassStatus extends OrchestrationResourceStatus {\n endpointCount?: number;\n healthyEndpointCount?: number;\n}\n\nexport type ToolClassManifest = OrchestrationResourceManifest<ToolClassSpec>;\n\nexport interface ToolClassResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: ToolClassSpec;\n status?: ToolClassStatus;\n}\n\nexport interface ToolExecutorCapability {\n toolClassRef: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n schemaDigest: string;\n effects?: ToolOperationEffect[];\n endpoint: string;\n capacity?: {\n maxConcurrent?: number;\n queueDepth?: number;\n };\n health?: {\n lastHeartbeat?: string;\n healthy: boolean;\n };\n}\n\nexport interface ToolExecutorSpec {\n nodeId?: string;\n selectors?: Record<string, string>;\n capabilities: ToolExecutorCapability[];\n trust?: 'trusted' | 'restricted' | 'quarantine';\n}\n\nexport interface ToolExecutorStatus extends OrchestrationResourceStatus {\n heartbeat?: string;\n healthy?: boolean;\n}\n\nexport type ToolExecutorManifest = OrchestrationResourceManifest<ToolExecutorSpec>;\n\nexport interface ToolExecutorResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: ToolExecutorSpec;\n status?: ToolExecutorStatus;\n}\n\nexport function createToolClassManifest(name: string, spec: ToolClassSpec): ToolClassManifest {\n return {\n apiVersion: TOOL_CLASS_API_VERSION,\n kind: TOOL_CLASS_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function createToolExecutorManifest(name: string, spec: ToolExecutorSpec): ToolExecutorManifest {\n return {\n apiVersion: TOOL_EXECUTOR_API_VERSION,\n kind: TOOL_EXECUTOR_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isToolClass(resource: { apiVersion?: string; kind?: string }): resource is ToolClassResource {\n return resource.apiVersion === TOOL_CLASS_API_VERSION && resource.kind === TOOL_CLASS_KIND;\n}\n\nexport function isToolExecutor(resource: { apiVersion?: string; kind?: string }): resource is ToolExecutorResource {\n return resource.apiVersion === TOOL_EXECUTOR_API_VERSION && resource.kind === TOOL_EXECUTOR_KIND;\n}\n\nexport const MODEL_CLASS_API_VERSION = 'models.memeloop.io/v1alpha1';\nexport const MODEL_CLASS_KIND = 'ModelClass';\n\nexport const MODEL_ENDPOINT_API_VERSION = 'models.memeloop.io/v1alpha1';\nexport const MODEL_ENDPOINT_KIND = 'ModelEndpoint';\n\nexport const MODEL_CALL_RECORD_API_VERSION = 'models.memeloop.io/v1alpha1';\nexport const MODEL_CALL_RECORD_KIND = 'ModelCallRecord';\n\nexport type ModelModality = 'text' | 'vision' | 'audio' | 'embedding';\n\nexport interface ModelClassCapabilities {\n streaming?: boolean;\n toolUse?: boolean;\n jsonMode?: boolean;\n systemPrompt?: boolean;\n}\n\n/**\n * Declarative model catalog entry. Carries identity, digest, capabilities,\n * residency, and cost metadata only — raw provider SDK clients, base URLs with\n * embedded credentials, and API keys must never appear here.\n */\nexport interface ModelClassSpec {\n description?: string;\n /** Provider family identifier, e.g. `openai`, `anthropic`, `ollama`. */\n provider: string;\n /** Provider model name, e.g. `gpt-4o-mini`, `qwen2.5:7b`. */\n model: string;\n version?: string;\n /** Content digest: local weights hash or provider snapshot identifier. */\n digest?: string;\n modalities?: ModelModality[];\n contextWindow?: number;\n maxOutputTokens?: number;\n capabilities?: ModelClassCapabilities;\n /** `local`, `cloud`, or a region/zone label constraining data residency. */\n dataResidency?: string;\n cost?: {\n inputPerMillion?: number;\n outputPerMillion?: number;\n currency?: string;\n };\n}\n\nexport interface ModelClassStatus extends OrchestrationResourceStatus {\n endpointCount?: number;\n healthyEndpointCount?: number;\n}\n\nexport type ModelClassManifest = OrchestrationResourceManifest<ModelClassSpec>;\n\nexport interface ModelClassResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: ModelClassSpec;\n status?: ModelClassStatus;\n}\n\n/**\n * Schedulable model serving endpoint. The endpoint string is an opaque driver\n * handle (e.g. `ollama://node-1/qwen2.5:7b` or `gateway://default`) and must\n * not embed credentials.\n */\nexport interface ModelEndpointSpec {\n modelClassRef: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n /** Must match the referenced ModelClass digest for schedulability. */\n modelDigest?: string;\n nodeId?: string;\n trust?: 'trusted' | 'restricted' | 'quarantine';\n endpoint: string;\n capacity?: {\n maxConcurrent?: number;\n tokensPerMinute?: number;\n };\n dataPolicy?: {\n classification?: string;\n retention?: string;\n };\n}\n\nexport interface ModelEndpointStatus extends OrchestrationResourceStatus {\n healthy?: boolean;\n heartbeat?: string;\n activeCalls?: number;\n}\n\nexport type ModelEndpointManifest = OrchestrationResourceManifest<ModelEndpointSpec>;\n\nexport interface ModelEndpointResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: ModelEndpointSpec;\n status?: ModelEndpointStatus;\n}\n\n/**\n * Audit and usage record for a single model call. Records carry usage and\n * classification metadata, never raw prompts, completions, or credentials.\n */\nexport interface ModelCallRecordSpec {\n modelClassRef: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n /** Immutable model artifact/provider snapshot selected for this call. */\n modelDigest?: string;\n endpointRef?: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n runRef?: OrchestrationOwnerReference;\n /** Immutable attempt number from the authorizing ModelAccessHandle. */\n runAttempt?: number;\n /** Bound actor identity asserted by the host, not self-reported. */\n caller?: string;\n /** Name of the ModelAccessHandle authorizing this call. */\n accessHandleRef?: string;\n /** Admission/policy snapshot bound into the authorizing handle. */\n policyDigest?: string;\n inputClassification?: string;\n outputClassification?: string;\n}\n\nexport interface ModelCallRecordStatus extends OrchestrationResourceStatus {\n phase?: 'Running' | 'Completed' | 'Failed' | 'Cancelled';\n usage?: {\n inputTokens?: number;\n outputTokens?: number;\n cost?: number;\n currency?: string;\n };\n latencyMs?: number;\n startedAt?: string;\n completedAt?: string;\n error?: OrchestrationErrorData;\n}\n\nexport type ModelCallRecordManifest = OrchestrationResourceManifest<ModelCallRecordSpec>;\n\nexport interface ModelCallRecordResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: ModelCallRecordSpec;\n status?: ModelCallRecordStatus;\n}\n\nexport function createModelClassManifest(name: string, spec: ModelClassSpec): ModelClassManifest {\n return {\n apiVersion: MODEL_CLASS_API_VERSION,\n kind: MODEL_CLASS_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function createModelEndpointManifest(name: string, spec: ModelEndpointSpec): ModelEndpointManifest {\n return {\n apiVersion: MODEL_ENDPOINT_API_VERSION,\n kind: MODEL_ENDPOINT_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function createModelCallRecordManifest(name: string, spec: ModelCallRecordSpec): ModelCallRecordManifest {\n return {\n apiVersion: MODEL_CALL_RECORD_API_VERSION,\n kind: MODEL_CALL_RECORD_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isModelClass(resource: { apiVersion?: string; kind?: string }): resource is ModelClassResource {\n return resource.apiVersion === MODEL_CLASS_API_VERSION && resource.kind === MODEL_CLASS_KIND;\n}\n\nexport function isModelEndpoint(resource: { apiVersion?: string; kind?: string }): resource is ModelEndpointResource {\n return resource.apiVersion === MODEL_ENDPOINT_API_VERSION && resource.kind === MODEL_ENDPOINT_KIND;\n}\n\nexport function isModelCallRecord(resource: { apiVersion?: string; kind?: string }): resource is ModelCallRecordResource {\n return resource.apiVersion === MODEL_CALL_RECORD_API_VERSION && resource.kind === MODEL_CALL_RECORD_KIND;\n}\n\nexport const SECURITY_PROFILE_API_VERSION = 'security.memeloop.io/v1alpha1';\nexport const SECURITY_PROFILE_KIND = 'SecurityProfile';\n\n/**\n * Reusable security posture referenced by workloads. The profile is applied\n * by trusted admission, never by the workload itself: for restricted and\n * quarantine trust classes the resolved tool-admission default is forced to\n * `deny` regardless of `toolAdmission.defaultAction`.\n */\nexport interface SecurityProfileSpec {\n description?: string;\n /** Trust class this profile applies to. */\n trustClass: NodeTrustClass;\n /** Tool admission overlay merged over the trust-class default policy. */\n toolAdmission?: ToolAdmissionPolicy;\n /** Model access constraints for workloads under this profile. */\n modelPolicy?: {\n allowedModelClasses?: string[];\n maxInputClassification?: DataClassification;\n };\n}\n\nexport interface SecurityProfileStatus extends OrchestrationResourceStatus {\n /** Number of workloads currently referencing this profile. */\n workloadCount?: number;\n}\n\nexport type SecurityProfileManifest = OrchestrationResourceManifest<SecurityProfileSpec>;\n\nexport interface SecurityProfileResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: SecurityProfileSpec;\n status?: SecurityProfileStatus;\n}\n\nexport function createSecurityProfileManifest(name: string, spec: SecurityProfileSpec): SecurityProfileManifest {\n return {\n apiVersion: SECURITY_PROFILE_API_VERSION,\n kind: SECURITY_PROFILE_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isSecurityProfile(resource: { apiVersion?: string; kind?: string }): resource is SecurityProfileResource {\n return resource.apiVersion === SECURITY_PROFILE_API_VERSION && resource.kind === SECURITY_PROFILE_KIND;\n}\n\nexport const POLICY_DECISION_API_VERSION = 'security.memeloop.io/v1alpha1';\nexport const POLICY_DECISION_KIND = 'PolicyDecision';\n\nexport type PersistedPolicyDecisionKind =\n | 'resource-admission'\n | 'placement'\n | 'tool-operation'\n | 'approval'\n | 'transition';\n\n/** Immutable decision evidence; only a pending approval's status may resolve. */\nexport interface PolicyDecisionSpec {\n subjectRef: {\n apiVersion: string;\n kind: string;\n name: string;\n namespace?: string;\n uid: string;\n generation: number;\n };\n decisionKind: PersistedPolicyDecisionKind;\n policyDigest: string;\n inputDigest: string;\n requestFingerprint: string;\n idempotencyKey: string;\n fencingEpoch: number;\n requestedBy: string;\n reasons: string[];\n obligations: string[];\n decidedAt: string;\n initialOutcome: 'allow' | 'deny' | 'pending';\n approval?: {\n subjectDigest: string;\n requestedBy: string;\n requestedAt: string;\n expiresAt: string;\n };\n}\n\nexport interface PolicyDecisionStatus extends OrchestrationResourceStatus {\n outcome: 'allow' | 'deny' | 'pending';\n decidedBy: string;\n decidedAt: string;\n reasons: string[];\n resolutionInputDigest?: string;\n}\n\nexport type PolicyDecisionManifest = OrchestrationResourceManifest<PolicyDecisionSpec>;\n\nexport interface PolicyDecisionResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: PolicyDecisionSpec;\n status?: PolicyDecisionStatus;\n}\n\nexport function createPolicyDecisionManifest(\n name: string,\n spec: PolicyDecisionSpec,\n): PolicyDecisionManifest {\n return {\n apiVersion: POLICY_DECISION_API_VERSION,\n kind: POLICY_DECISION_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isPolicyDecision(\n resource: { apiVersion?: string; kind?: string },\n): resource is PolicyDecisionResource {\n return resource.apiVersion === POLICY_DECISION_API_VERSION &&\n resource.kind === POLICY_DECISION_KIND;\n}\n\nexport const AUDIT_RECORD_API_VERSION = 'audit.memeloop.io/v1alpha1';\nexport const AUDIT_RECORD_KIND = 'AuditRecord';\n\n/**\n * Immutable, metadata-only audit/telemetry evidence. The record digest covers\n * every field except itself and links to the preceding record in the named\n * stream. Raw request/response bodies and credentials have no representation.\n */\nexport interface AuditRecordSpec {\n stream: string;\n sequence: number;\n resourceUid: string;\n recordKind: 'audit' | 'event' | 'metric' | 'trace';\n receivedAt: string;\n actor: {\n id: string;\n kind: 'controller' | 'verifier' | 'admin';\n };\n policyDigest: string;\n capabilityDigest: string;\n effect: 'read' | 'create' | 'update' | 'delete' | 'execute' | 'decision' | 'security';\n provenance: {\n source: 'controller' | 'gateway' | 'driver' | 'worker' | 'operator';\n producer: string;\n subject?: string;\n };\n attributes: Record<string, string>;\n data:\n | {\n kind: 'audit';\n action: string;\n outcome: 'success' | 'denied' | 'failure';\n reasonCode?: string;\n }\n | {\n kind: 'event';\n name: string;\n severity: 'debug' | 'info' | 'warning' | 'error' | 'critical';\n }\n | {\n kind: 'metric';\n name: string;\n value: number;\n unit: string;\n }\n | {\n kind: 'trace';\n name: string;\n traceId: string;\n spanId: string;\n durationMs: number;\n status: 'ok' | 'error';\n };\n previousDigest?: string;\n recordDigest: string;\n requestFingerprint: string;\n idempotencyDigest: string;\n fencingEpoch: number;\n}\n\nexport type AuditRecordManifest = OrchestrationResourceManifest<AuditRecordSpec>;\n\nexport interface AuditRecordResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: AuditRecordSpec;\n status?: OrchestrationResourceStatus;\n}\n\nexport function createAuditRecordManifest(\n name: string,\n spec: AuditRecordSpec,\n): AuditRecordManifest {\n return {\n apiVersion: AUDIT_RECORD_API_VERSION,\n kind: AUDIT_RECORD_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isAuditRecord(\n resource: { apiVersion?: string; kind?: string },\n): resource is AuditRecordResource {\n return resource.apiVersion === AUDIT_RECORD_API_VERSION &&\n resource.kind === AUDIT_RECORD_KIND;\n}\n\nexport const NETWORK_CLASS_API_VERSION = 'network.memeloop.io/v1alpha1';\nexport const NETWORK_CLASS_KIND = 'NetworkClass';\n\nexport const NETWORK_ATTACHMENT_API_VERSION = 'network.memeloop.io/v1alpha1';\nexport const NETWORK_ATTACHMENT_KIND = 'NetworkAttachment';\n\nexport interface NetworkEgressRule {\n /** Host, domain suffix, or CIDR, e.g. `api.openai.com` or `10.0.0.0/8`. */\n target: string;\n ports?: number[];\n protocol?: 'tcp' | 'udp' | 'http' | 'https' | 'any';\n action: 'allow' | 'deny';\n}\n\n/**\n * CNI-like network desired state. `enforcement: required` means the workload\n * must not start unless the driver can enforce every configured feature;\n * `best-effort` allows partial enforcement with recorded degradation.\n */\nexport interface NetworkClassSpec {\n description?: string;\n /** NetworkDriver name responsible for this class. */\n driver: string;\n dns?: {\n policy?: 'default' | 'none' | 'custom';\n servers?: string[];\n searchDomains?: string[];\n };\n proxy?: {\n httpProxy?: string;\n httpsProxy?: string;\n noProxy?: string[];\n /** When true, traffic bypassing the proxy must be blocked. */\n mandatory?: boolean;\n };\n ingress?: {\n defaultAction?: 'allow' | 'deny';\n allow?: Array<{\n from?: string;\n ports?: number[];\n }>;\n };\n egress?: {\n defaultAction: 'allow' | 'deny';\n rules?: NetworkEgressRule[];\n };\n serviceAccess?: {\n allowControlPlane?: boolean;\n allowClusterServices?: boolean;\n allowModelGateway?: boolean;\n };\n bandwidth?: {\n ingressKbps?: number;\n egressKbps?: number;\n };\n dataPolicy?: {\n classification?: DataClassification;\n retention?: string;\n };\n enforcement: 'required' | 'best-effort';\n}\n\nexport interface NetworkClassStatus extends OrchestrationResourceStatus {\n attachmentCount?: number;\n}\n\nexport type NetworkClassManifest = OrchestrationResourceManifest<NetworkClassSpec>;\n\nexport interface NetworkClassResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: NetworkClassSpec;\n status?: NetworkClassStatus;\n}\n\nexport interface NetworkAttachmentSpec {\n networkClassRef: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n workloadRef?: OrchestrationOwnerReference;\n /** Exact AgentRun whose sandbox and authority this attachment belongs to. */\n runRef?: OrchestrationOwnerReference;\n nodeId?: string;\n}\n\nexport interface NetworkAttachmentStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Preparing' | 'Attached' | 'Failed' | 'Detached';\n /** Node and driver selected independently from workload execution. */\n assignedNode?: string;\n assignedDriver?: string;\n /** Fences the placement decision and the NetworkClass version it validated. */\n binding?: {\n leaseEpoch: string;\n networkClassResourceVersion: string;\n boundAt: string;\n };\n /**\n * Durable claim written before prepare() may create host-side state.\n * A new lease epoch must not blindly repeat an unconfirmed prepare.\n */\n executionClaim?: {\n leaseEpoch: string;\n claimedAt: string;\n };\n /** Opaque driver handle; consumers must never parse it. */\n handle?: string;\n addresses?: string[];\n routes?: string[];\n dns?: {\n servers?: string[];\n };\n /** Features the driver could not enforce under a best-effort class. */\n degraded?: string[];\n attachedAt?: string;\n /** Set by the workload owner after execution; the node driver must release before Detached. */\n releaseRequestedAt?: string;\n detachedAt?: string;\n error?: OrchestrationErrorData;\n}\n\nexport type NetworkAttachmentManifest = OrchestrationResourceManifest<NetworkAttachmentSpec>;\n\nexport interface NetworkAttachmentResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: NetworkAttachmentSpec;\n status?: NetworkAttachmentStatus;\n}\n\nexport function createNetworkClassManifest(name: string, spec: NetworkClassSpec): NetworkClassManifest {\n return {\n apiVersion: NETWORK_CLASS_API_VERSION,\n kind: NETWORK_CLASS_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function createNetworkAttachmentManifest(name: string, spec: NetworkAttachmentSpec): NetworkAttachmentManifest {\n return {\n apiVersion: NETWORK_ATTACHMENT_API_VERSION,\n kind: NETWORK_ATTACHMENT_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isNetworkClass(resource: { apiVersion?: string; kind?: string }): resource is NetworkClassResource {\n return resource.apiVersion === NETWORK_CLASS_API_VERSION && resource.kind === NETWORK_CLASS_KIND;\n}\n\nexport function isNetworkAttachment(resource: { apiVersion?: string; kind?: string }): resource is NetworkAttachmentResource {\n return resource.apiVersion === NETWORK_ATTACHMENT_API_VERSION && resource.kind === NETWORK_ATTACHMENT_KIND;\n}\n\nexport const STORAGE_CLASS_API_VERSION = 'storage.memeloop.io/v1alpha1';\nexport const STORAGE_CLASS_KIND = 'StorageClass';\nexport const VOLUME_CLAIM_API_VERSION = 'storage.memeloop.io/v1alpha1';\nexport const VOLUME_CLAIM_KIND = 'AgentVolumeClaim';\nexport const VOLUME_API_VERSION = 'storage.memeloop.io/v1alpha1';\nexport const VOLUME_KIND = 'AgentVolume';\nexport const SNAPSHOT_API_VERSION = 'storage.memeloop.io/v1alpha1';\nexport const SNAPSHOT_KIND = 'AgentSnapshot';\n\nexport type VolumeAccessMode = 'ReadWriteOnce' | 'ReadOnlyMany' | 'ReadWriteMany';\n\n/** CSI-like storage class: provisioning and replication policy. */\nexport interface StorageClassSpec {\n description?: string;\n /** StorageDriver name responsible for this class. */\n driver: string;\n replication?: {\n /** Desired replica count across fault domains (1 = no replication). */\n factor?: number;\n /** Fault-domain labels replicas must be spread across (e.g. `node`, `zone`). */\n faultDomains?: string[];\n /** Rebuild replicas automatically after loss. */\n autoRebuild?: boolean;\n };\n encryption?: {\n enabled?: boolean;\n /** Reference to a key in the credential domain (never key material). */\n keyRef?: string;\n };\n allowedAccessModes?: VolumeAccessMode[];\n snapshotSupport?: boolean;\n backup?: {\n /** Cron-like schedule expression evaluated by the backup controller. */\n schedule?: string;\n retentionCount?: number;\n };\n dataPolicy?: {\n classification?: DataClassification;\n retention?: string;\n };\n}\n\nexport interface StorageClassStatus extends OrchestrationResourceStatus {\n volumeCount?: number;\n healthyVolumeCount?: number;\n}\n\nexport type StorageClassManifest = OrchestrationResourceManifest<StorageClassSpec>;\n\nexport interface StorageClassResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: StorageClassSpec;\n status?: StorageClassStatus;\n}\n\n/** PVC-like claim: a workload's request for storage. */\nexport interface AgentVolumeClaimSpec {\n storageClassRef: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n accessMode: VolumeAccessMode;\n sizeBytes?: number;\n selector?: Record<string, string>;\n /** Restore from a snapshot when provisioning. */\n dataSourceRef?: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n}\n\nexport interface AgentVolumeClaimStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Provisioning' | 'Bound' | 'Lost' | 'Failed';\n assignedNode?: string;\n assignedDriver?: string;\n binding?: {\n leaseEpoch: string;\n storageClassResourceVersion: string;\n boundAt: string;\n };\n provisionClaim?: {\n leaseEpoch: string;\n claimedAt: string;\n };\n volumeRef?: {\n apiVersion: string;\n kind: string;\n name: string;\n uid?: string;\n };\n error?: OrchestrationErrorData;\n}\n\nexport type AgentVolumeClaimManifest = OrchestrationResourceManifest<AgentVolumeClaimSpec>;\n\nexport interface AgentVolumeClaimResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: AgentVolumeClaimSpec;\n status?: AgentVolumeClaimStatus;\n}\n\nexport interface AgentVolumeReplicaStatus {\n nodeId: string;\n state: 'healthy' | 'degraded' | 'rebuilding' | 'offline';\n /** Verified content hash of this replica (must equal the volume contentHash). */\n contentHash?: string;\n updatedAt?: string;\n}\n\n/** PV-like provisioned volume. `driverHandle` is opaque and never parsed by consumers. */\nexport interface AgentVolumeSpec {\n storageClassRef: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n claimRef?: OrchestrationOwnerReference;\n /** Opaque driver handle for the provisioned volume. */\n driverHandle: string;\n capacityBytes?: number;\n topology?: {\n nodeId?: string;\n zone?: string;\n };\n accessModes?: VolumeAccessMode[];\n}\n\nexport interface AgentVolumeStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Available' | 'Bound' | 'Published' | 'Failed';\n replicas?: AgentVolumeReplicaStatus[];\n /** Last verified content hash; the replication source of truth. */\n contentHash?: string;\n /** Current primary replica node; transfers originate only from the primary. */\n primaryNodeId?: string;\n /** Monotonically increasing fencing epoch, bumped on every primary change. */\n primaryEpoch?: number;\n publishedTo?: Array<{\n nodeId?: string;\n workloadRef?: OrchestrationOwnerReference;\n }>;\n health?: 'healthy' | 'degraded' | 'rebuilding' | 'failed';\n}\n\nexport type AgentVolumeManifest = OrchestrationResourceManifest<AgentVolumeSpec>;\n\nexport interface AgentVolumeResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: AgentVolumeSpec;\n status?: AgentVolumeStatus;\n}\n\n/** Point-in-time snapshot of a volume; restorable into new claims. */\nexport interface AgentSnapshotSpec {\n sourceVolumeRef: {\n apiVersion: string;\n kind: string;\n name: string;\n };\n snapshotClass?: string;\n}\n\nexport interface AgentSnapshotStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Ready' | 'Failed';\n readyToUse?: boolean;\n restoreSizeBytes?: number;\n /** Opaque driver handle for the snapshot. */\n driverHandle?: string;\n createdAt?: string;\n}\n\nexport type AgentSnapshotManifest = OrchestrationResourceManifest<AgentSnapshotSpec>;\n\nexport interface AgentSnapshotResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: AgentSnapshotSpec;\n status?: AgentSnapshotStatus;\n}\n\nexport function createStorageClassManifest(name: string, spec: StorageClassSpec): StorageClassManifest {\n return {\n apiVersion: STORAGE_CLASS_API_VERSION,\n kind: STORAGE_CLASS_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function createVolumeClaimManifest(name: string, spec: AgentVolumeClaimSpec): AgentVolumeClaimManifest {\n return {\n apiVersion: VOLUME_CLAIM_API_VERSION,\n kind: VOLUME_CLAIM_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function createVolumeManifest(name: string, spec: AgentVolumeSpec): AgentVolumeManifest {\n return {\n apiVersion: VOLUME_API_VERSION,\n kind: VOLUME_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function createSnapshotManifest(name: string, spec: AgentSnapshotSpec): AgentSnapshotManifest {\n return {\n apiVersion: SNAPSHOT_API_VERSION,\n kind: SNAPSHOT_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isStorageClass(resource: { apiVersion?: string; kind?: string }): resource is StorageClassResource {\n return resource.apiVersion === STORAGE_CLASS_API_VERSION && resource.kind === STORAGE_CLASS_KIND;\n}\n\nexport function isVolumeClaim(resource: { apiVersion?: string; kind?: string }): resource is AgentVolumeClaimResource {\n return resource.apiVersion === VOLUME_CLAIM_API_VERSION && resource.kind === VOLUME_CLAIM_KIND;\n}\n\nexport function isVolume(resource: { apiVersion?: string; kind?: string }): resource is AgentVolumeResource {\n return resource.apiVersion === VOLUME_API_VERSION && resource.kind === VOLUME_KIND;\n}\n\nexport function isSnapshot(resource: { apiVersion?: string; kind?: string }): resource is AgentSnapshotResource {\n return resource.apiVersion === SNAPSHOT_API_VERSION && resource.kind === SNAPSHOT_KIND;\n}\n\nexport const CREDENTIAL_GRANT_API_VERSION = 'security.memeloop.io/v1alpha1';\nexport const CREDENTIAL_GRANT_KIND = 'CredentialGrant';\n\n/**\n * JIT credential authorization (plan 24.46). The resource records grant\n * metadata only — the opaque handle lives in the credential domain and raw\n * secret material never appears in spec or status.\n */\nexport interface CredentialGrantSpec {\n runRef: {\n apiVersion: string;\n kind: string;\n name: string;\n uid: string;\n };\n attempt: number;\n /** Fingerprint of the worker's ephemeral public key. */\n workerKey: string;\n /** Target system the credential acts on (e.g. `ssh://node-7`, `model:openai/gpt-4o`). */\n target: string;\n /** Operation the credential authorizes (e.g. `exec`, `generate`, `read`). */\n method: string;\n /** Audience the resulting handle is valid for. */\n audience: string;\n policyDigest: string;\n budget?: {\n maxCalls?: number;\n maxCost?: number;\n currency?: string;\n };\n /** Requested TTL in milliseconds; the broker caps it. */\n ttlMs?: number;\n}\n\nexport interface CredentialGrantStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Issuing' | 'Issued' | 'Renewed' | 'Revoked' | 'Expired' | 'Failed';\n assignedNode?: string;\n assignedBroker?: string;\n binding?: {\n leaseEpoch: string;\n boundAt: string;\n };\n issuanceClaim?: {\n leaseEpoch: string;\n claimedAt: string;\n };\n /** Opaque handle reference in the credential domain — never the handle itself. */\n handleRef?: string;\n issuedAt?: string;\n expiresAt?: string;\n renewedAt?: string;\n revokedAt?: string;\n /** Exposure assessment used to decide post-task rotation. */\n exposure?: 'none' | 'worker-visible' | 'potentially-exposed';\n rotationRequired?: boolean;\n rotationReason?: string;\n error?: OrchestrationErrorData;\n}\n\nexport type CredentialGrantManifest = OrchestrationResourceManifest<CredentialGrantSpec>;\n\nexport interface CredentialGrantResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: CredentialGrantSpec;\n status?: CredentialGrantStatus;\n}\n\nexport function createCredentialGrantManifest(name: string, spec: CredentialGrantSpec): CredentialGrantManifest {\n return {\n apiVersion: CREDENTIAL_GRANT_API_VERSION,\n kind: CREDENTIAL_GRANT_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isCredentialGrant(resource: { apiVersion?: string; kind?: string }): resource is CredentialGrantResource {\n return resource.apiVersion === CREDENTIAL_GRANT_API_VERSION && resource.kind === CREDENTIAL_GRANT_KIND;\n}\n\nexport const ARTIFACT_RECORD_API_VERSION = 'artifacts.memeloop.io/v1alpha1';\nexport const ARTIFACT_RECORD_KIND = 'ArtifactRecord';\n\nexport type ArtifactTrust = 'trusted' | 'restricted' | 'quarantine' | 'untrusted';\n\nexport type ArtifactDestination = 'prompt' | 'volume' | 'backup' | 'knowledge';\n\nexport type ArtifactReviewKind = 'scan' | 'sanitize' | 'verify';\n\nexport interface ArtifactReviewEvidence {\n kind: ArtifactReviewKind;\n outcome: 'passed' | 'failed';\n reviewer: string;\n contentHash: string;\n policyDigest: string;\n destinations: ArtifactDestination[];\n /** Narrow properties certified by the reviewer; never implies general trust. */\n properties?: string[];\n recordedAt: string;\n}\n\n/**\n * Content-addressed artifact with provenance and trust (plan 24.47). Derived\n * content inherits the lowest trust of its inputs; untrusted or unverified\n * content cannot enter trusted prompts, volumes, backups, or knowledge\n * ingestion without explicit policy and a verifier pass.\n */\nexport interface ArtifactRecordSpec {\n /** Content hash (e.g. `sha256:...`); the storage address. */\n contentHash: string;\n sizeBytes?: number;\n mimeType?: string;\n /** Producing run and its trust at production time. */\n producer?: {\n runRef?: OrchestrationOwnerReference;\n trust: ArtifactTrust;\n };\n /** Parent artifacts this one derives from. */\n parents?: Array<{\n apiVersion: string;\n kind: string;\n name: string;\n }>;\n trust: ArtifactTrust;\n}\n\nexport interface ArtifactRecordStatus extends OrchestrationResourceStatus {\n /** Append-only evidence written only by the trusted artifact review actor. */\n reviews?: ArtifactReviewEvidence[];\n quarantined?: boolean;\n quarantineReason?: string;\n /** Downstream artifact names derived from this one (lineage). */\n derivedBy?: string[];\n}\n\nexport type ArtifactRecordManifest = OrchestrationResourceManifest<ArtifactRecordSpec>;\n\nexport interface ArtifactRecordResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: ArtifactRecordSpec;\n status?: ArtifactRecordStatus;\n}\n\nexport function createArtifactRecordManifest(name: string, spec: ArtifactRecordSpec): ArtifactRecordManifest {\n return {\n apiVersion: ARTIFACT_RECORD_API_VERSION,\n kind: ARTIFACT_RECORD_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isArtifactRecord(resource: { apiVersion?: string; kind?: string }): resource is ArtifactRecordResource {\n return resource.apiVersion === ARTIFACT_RECORD_API_VERSION && resource.kind === ARTIFACT_RECORD_KIND;\n}\n\n// ─── DriverManifest (drivers.memeloop.io/v1alpha1) ────────────────────\n\nexport const DRIVER_MANIFEST_API_VERSION = 'drivers.memeloop.io/v1alpha1';\nexport const DRIVER_MANIFEST_KIND = 'DriverManifest';\n\nexport type InfrastructureDriverType =\n | 'control-store'\n | 'loop-runtime'\n | 'tool-catalog'\n | 'tool-execution'\n | 'model-provider'\n | 'network'\n | 'storage'\n | 'credential'\n | 'artifact'\n | 'identity-attestation'\n | 'policy-approval'\n | 'audit-telemetry'\n | 'external-orchestrator';\n\nexport type DriverManifestConformance =\n | {\n suiteVersion: string;\n status: 'not-run';\n }\n | {\n suiteVersion: string;\n status: 'failed';\n failedAt: string;\n failure: string;\n }\n | {\n suiteVersion: string;\n status: 'passed';\n passedAt: string;\n /** Content digest of the exact golden fixture/result bundle. */\n fixtureDigest: string;\n };\n\n/**\n * Control-plane representation of a registered driver (plan §11, 24.62).\n * A RuntimeClass/NetworkClass/ModelClass/scheduler can only reference a\n * driver whose manifest is registered and conformance-checked; external\n * orchestrator drivers register through the CLI discovery loader.\n */\nexport interface DriverManifestSpec {\n driverType: InfrastructureDriverType;\n /** Driver package version (from getCapabilities or the package manifest). */\n version: string;\n execution: {\n location: 'controller' | 'node' | 'worker' | 'external';\n transport: 'in-process' | 'stdio' | 'utility-process' | 'http' | 'peer-rpc' | 'container-api' | 'other';\n };\n supportedTrustClasses: NodeTrustClass[];\n resourceKinds: string[];\n capabilities: Record<string, boolean | string | number>;\n downgradeBehavior: 'reject' | 'explicit-degrade';\n requiredHostPrivileges: string[];\n isolation: {\n boundary: 'none' | 'process' | 'namespace' | 'host' | 'external';\n threatAssumptions: string[];\n };\n configuration: {\n /** Stable reference to the schema used to validate non-secret configuration. */\n schemaRef: string;\n /** Names of opaque SecretRef fields; never secret values. */\n secretRefs: string[];\n };\n health: {\n mode: 'method' | 'endpoint';\n endpoint?: string;\n };\n lifecycle: {\n discoverable: boolean;\n hotReload: boolean;\n gracefulShutdown: boolean;\n };\n conformance: DriverManifestConformance;\n supportsCancellation: boolean;\n supportsBackpressure: boolean;\n supportsAdoption: boolean;\n supportsFencing: boolean;\n /** External orchestrators: the resource kinds this driver manages. */\n manages?: Array<'AgentWorkload' | 'ToolOperation'>;\n /** External orchestrators: co-located scheduling support. */\n supportsColocation?: boolean;\n}\n\nexport interface DriverManifestStatus extends OrchestrationResourceStatus {\n phase?: 'Pending' | 'Ready' | 'Failed';\n registeredAt?: string;\n error?: OrchestrationErrorData;\n}\n\nexport type DriverManifestManifest = OrchestrationResourceManifest<DriverManifestSpec>;\n\nexport interface DriverManifestResource extends OrchestrationTypeMeta {\n metadata: OrchestrationObjectMetadata;\n spec: DriverManifestSpec;\n status?: DriverManifestStatus;\n}\n\nexport function createDriverManifestManifest(name: string, spec: DriverManifestSpec): DriverManifestManifest {\n return {\n apiVersion: DRIVER_MANIFEST_API_VERSION,\n kind: DRIVER_MANIFEST_KIND,\n metadata: { name },\n spec,\n };\n}\n\nexport function isDriverManifest(resource: { apiVersion?: string; kind?: string }): resource is DriverManifestResource {\n return resource.apiVersion === DRIVER_MANIFEST_API_VERSION && resource.kind === DRIVER_MANIFEST_KIND;\n}\n\n/** A class may only select a manifest whose current conformance evidence passed. */\nexport function isDriverManifestAdmitted(resource: DriverManifestResource): boolean {\n return resource.status?.phase === 'Ready' && resource.spec.conformance.status === 'passed';\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OrchestrationError
|
|
3
|
+
} from "./chunk-FWSY5HOA.js";
|
|
4
|
+
|
|
5
|
+
// src/orchestration/remoteClient.ts
|
|
6
|
+
var REMOTE_ORCHESTRATION_PROTOCOL = "memeloop.resource.v1";
|
|
7
|
+
var REMOTE_OPERATIONS = /* @__PURE__ */ new Set([
|
|
8
|
+
"capabilities",
|
|
9
|
+
"apply",
|
|
10
|
+
"get",
|
|
11
|
+
"list",
|
|
12
|
+
"watch",
|
|
13
|
+
"delete"
|
|
14
|
+
]);
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
function errorData(error) {
|
|
19
|
+
if (error instanceof OrchestrationError) {
|
|
20
|
+
return {
|
|
21
|
+
code: error.code,
|
|
22
|
+
message: error.message,
|
|
23
|
+
retryable: error.retryable,
|
|
24
|
+
...error.retryAfterMs !== void 0 ? { retryAfterMs: error.retryAfterMs } : {},
|
|
25
|
+
...error.reason !== void 0 ? { reason: error.reason } : {},
|
|
26
|
+
...error.details !== void 0 ? { details: error.details } : {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
code: "INTERNAL",
|
|
31
|
+
message: error instanceof Error ? error.message : String(error),
|
|
32
|
+
retryable: false
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function throwResponseError(response) {
|
|
36
|
+
throw new OrchestrationError(response.error);
|
|
37
|
+
}
|
|
38
|
+
function assertResponse(request, response) {
|
|
39
|
+
if (!isRecord(response) || response.protocol !== REMOTE_ORCHESTRATION_PROTOCOL || response.requestId !== request.requestId || typeof response.ok !== "boolean" || response.ok && !("result" in response) || !response.ok && (!isRecord(response.error) || typeof response.error.code !== "string" || typeof response.error.message !== "string" || typeof response.error.retryable !== "boolean")) {
|
|
40
|
+
throw new OrchestrationError({
|
|
41
|
+
code: "INVALID",
|
|
42
|
+
message: "remote orchestration response correlation or protocol mismatch",
|
|
43
|
+
retryable: false
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
var requestSequence = 0;
|
|
48
|
+
function createRemoteOrchestrationClient(transport, options = {}) {
|
|
49
|
+
const createRequestId = options.createRequestId ?? (() => `resource-${Date.now().toString(36)}-${(++requestSequence).toString(36)}`);
|
|
50
|
+
function makeRequest(operation, payload) {
|
|
51
|
+
return {
|
|
52
|
+
protocol: REMOTE_ORCHESTRATION_PROTOCOL,
|
|
53
|
+
requestId: createRequestId(),
|
|
54
|
+
operation,
|
|
55
|
+
payload
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async function request(operation, payload, signal) {
|
|
59
|
+
const envelope = makeRequest(operation, payload);
|
|
60
|
+
const response = await transport.request(envelope, { signal });
|
|
61
|
+
assertResponse(envelope, response);
|
|
62
|
+
if (!response.ok) throwResponseError(response);
|
|
63
|
+
return response.result;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
getCapabilities() {
|
|
67
|
+
return request("capabilities", {});
|
|
68
|
+
},
|
|
69
|
+
apply(resource, applyOptions) {
|
|
70
|
+
return request("apply", {
|
|
71
|
+
resource,
|
|
72
|
+
...applyOptions ? { options: applyOptions } : {}
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
get(reference, getOptions) {
|
|
76
|
+
return request("get", {
|
|
77
|
+
reference,
|
|
78
|
+
...getOptions ? { options: getOptions } : {}
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
list(query, listOptions) {
|
|
82
|
+
return request("list", {
|
|
83
|
+
query,
|
|
84
|
+
...listOptions ? { options: listOptions } : {}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
async *watch(query, watchOptions) {
|
|
88
|
+
const envelope = makeRequest("watch", {
|
|
89
|
+
query,
|
|
90
|
+
...watchOptions ? {
|
|
91
|
+
options: {
|
|
92
|
+
...watchOptions,
|
|
93
|
+
signal: void 0
|
|
94
|
+
}
|
|
95
|
+
} : {}
|
|
96
|
+
});
|
|
97
|
+
for await (const response of transport.watch(envelope, {
|
|
98
|
+
signal: watchOptions?.signal
|
|
99
|
+
})) {
|
|
100
|
+
assertResponse(envelope, response);
|
|
101
|
+
if (!response.ok) throwResponseError(response);
|
|
102
|
+
yield response.result;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
delete(reference, deleteOptions) {
|
|
106
|
+
return request("delete", {
|
|
107
|
+
reference,
|
|
108
|
+
...deleteOptions ? { options: deleteOptions } : {}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function createReadOnlyOrchestrationClient(client, options = {}) {
|
|
114
|
+
const allowedKinds = options.allowedResourceKinds ? new Set(options.allowedResourceKinds) : void 0;
|
|
115
|
+
function assertAllowedKind(kind) {
|
|
116
|
+
if (!allowedKinds || allowedKinds.has(kind)) return;
|
|
117
|
+
throw new OrchestrationError({
|
|
118
|
+
code: "FORBIDDEN",
|
|
119
|
+
message: `remote orchestration access to resource kind '${kind}' is forbidden`,
|
|
120
|
+
retryable: false
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function forbidden(operation) {
|
|
124
|
+
throw new OrchestrationError({
|
|
125
|
+
code: "FORBIDDEN",
|
|
126
|
+
message: `remote orchestration operation '${operation}' is read-only`,
|
|
127
|
+
retryable: false
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
async getCapabilities() {
|
|
132
|
+
const capabilities = await client.getCapabilities();
|
|
133
|
+
return {
|
|
134
|
+
operations: ["get", "list", "watch"],
|
|
135
|
+
resourceKinds: capabilities.resourceKinds.filter((kind) => allowedKinds ? allowedKinds.has(kind) : true),
|
|
136
|
+
interfaces: capabilities.interfaces.includes("resource") ? ["resource"] : []
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
async apply() {
|
|
140
|
+
forbidden("apply");
|
|
141
|
+
},
|
|
142
|
+
async get(reference, getOptions) {
|
|
143
|
+
assertAllowedKind(reference.kind);
|
|
144
|
+
return await client.get(reference, getOptions);
|
|
145
|
+
},
|
|
146
|
+
async list(query, listOptions) {
|
|
147
|
+
assertAllowedKind(query.kind);
|
|
148
|
+
return await client.list(query, listOptions);
|
|
149
|
+
},
|
|
150
|
+
async *watch(query, watchOptions) {
|
|
151
|
+
assertAllowedKind(query.kind);
|
|
152
|
+
yield* client.watch(query, watchOptions);
|
|
153
|
+
},
|
|
154
|
+
async delete() {
|
|
155
|
+
forbidden("delete");
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function createNamespacedOrchestrationClient(client, options) {
|
|
160
|
+
const namespace = options.namespace.trim();
|
|
161
|
+
if (!namespace || namespace.length > 253) {
|
|
162
|
+
throw new TypeError("namespace must contain between 1 and 253 characters");
|
|
163
|
+
}
|
|
164
|
+
const allowedKinds = new Set(options.allowedResourceKinds);
|
|
165
|
+
const mutableKinds = new Set(options.mutableResourceKinds ?? options.allowedResourceKinds);
|
|
166
|
+
for (const kind of mutableKinds) {
|
|
167
|
+
if (!allowedKinds.has(kind)) {
|
|
168
|
+
throw new TypeError(`mutable resource kind '${kind}' must also be allowed`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function assertAllowedKind(kind) {
|
|
172
|
+
if (allowedKinds.has(kind)) return;
|
|
173
|
+
throw new OrchestrationError({
|
|
174
|
+
code: "FORBIDDEN",
|
|
175
|
+
message: `remote orchestration access to resource kind '${kind}' is forbidden`,
|
|
176
|
+
retryable: false
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function bindNamespace(metadata) {
|
|
180
|
+
if (metadata.namespace !== void 0 && metadata.namespace !== namespace) {
|
|
181
|
+
throw new OrchestrationError({
|
|
182
|
+
code: "FORBIDDEN",
|
|
183
|
+
message: `remote orchestration access outside namespace '${namespace}' is forbidden`,
|
|
184
|
+
retryable: false
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return { ...metadata, namespace };
|
|
188
|
+
}
|
|
189
|
+
function assertMutableKind(kind) {
|
|
190
|
+
assertAllowedKind(kind);
|
|
191
|
+
if (mutableKinds.has(kind)) return;
|
|
192
|
+
throw new OrchestrationError({
|
|
193
|
+
code: "FORBIDDEN",
|
|
194
|
+
message: `remote orchestration mutation of resource kind '${kind}' is forbidden`,
|
|
195
|
+
retryable: false
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
async getCapabilities() {
|
|
200
|
+
const capabilities = await client.getCapabilities();
|
|
201
|
+
const resourceKinds = capabilities.resourceKinds.filter((kind) => allowedKinds.has(kind));
|
|
202
|
+
const resourceOperations = Object.fromEntries(
|
|
203
|
+
resourceKinds.map((kind) => {
|
|
204
|
+
const sourceOperations = capabilities.resourceOperations?.[kind] ?? capabilities.operations;
|
|
205
|
+
return [
|
|
206
|
+
kind,
|
|
207
|
+
sourceOperations.filter((operation) => mutableKinds.has(kind) || operation !== "apply" && operation !== "delete")
|
|
208
|
+
];
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
return {
|
|
212
|
+
operations: capabilities.operations,
|
|
213
|
+
resourceKinds,
|
|
214
|
+
resourceOperations,
|
|
215
|
+
interfaces: capabilities.interfaces.includes("resource") ? ["resource"] : []
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
async apply(resource, applyOptions) {
|
|
219
|
+
assertMutableKind(resource.kind);
|
|
220
|
+
return await client.apply(
|
|
221
|
+
{
|
|
222
|
+
...resource,
|
|
223
|
+
metadata: bindNamespace(resource.metadata)
|
|
224
|
+
},
|
|
225
|
+
applyOptions
|
|
226
|
+
);
|
|
227
|
+
},
|
|
228
|
+
async get(reference, getOptions) {
|
|
229
|
+
assertAllowedKind(reference.kind);
|
|
230
|
+
return await client.get(bindNamespace(reference), getOptions);
|
|
231
|
+
},
|
|
232
|
+
async list(query, listOptions) {
|
|
233
|
+
assertAllowedKind(query.kind);
|
|
234
|
+
return await client.list(bindNamespace(query), listOptions);
|
|
235
|
+
},
|
|
236
|
+
watch(query, watchOptions) {
|
|
237
|
+
assertAllowedKind(query.kind);
|
|
238
|
+
return client.watch(bindNamespace(query), watchOptions);
|
|
239
|
+
},
|
|
240
|
+
async delete(reference, deleteOptions) {
|
|
241
|
+
assertMutableKind(reference.kind);
|
|
242
|
+
return await client.delete(bindNamespace(reference), deleteOptions);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function requirePayload(payload, key) {
|
|
247
|
+
if (!(key in payload)) {
|
|
248
|
+
throw new OrchestrationError({
|
|
249
|
+
code: "INVALID",
|
|
250
|
+
message: `remote orchestration request is missing payload.${key}`,
|
|
251
|
+
retryable: false
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return payload[key];
|
|
255
|
+
}
|
|
256
|
+
function success(request, result) {
|
|
257
|
+
return {
|
|
258
|
+
protocol: REMOTE_ORCHESTRATION_PROTOCOL,
|
|
259
|
+
requestId: request.requestId,
|
|
260
|
+
ok: true,
|
|
261
|
+
result
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function failure(request, error) {
|
|
265
|
+
const requestRecord = isRecord(request) ? request : void 0;
|
|
266
|
+
return {
|
|
267
|
+
protocol: REMOTE_ORCHESTRATION_PROTOCOL,
|
|
268
|
+
requestId: typeof requestRecord?.requestId === "string" ? requestRecord.requestId : "invalid",
|
|
269
|
+
ok: false,
|
|
270
|
+
error: errorData(error)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function createRemoteOrchestrationHandler(client) {
|
|
274
|
+
function validate(request) {
|
|
275
|
+
if (!isRecord(request) || request.protocol !== REMOTE_ORCHESTRATION_PROTOCOL || typeof request.requestId !== "string" || !request.requestId || request.requestId.length > 256 || !REMOTE_OPERATIONS.has(request.operation) || !isRecord(request.payload)) {
|
|
276
|
+
throw new OrchestrationError({
|
|
277
|
+
code: "INVALID",
|
|
278
|
+
message: "invalid remote orchestration request envelope",
|
|
279
|
+
retryable: false
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
async request(request) {
|
|
285
|
+
try {
|
|
286
|
+
validate(request);
|
|
287
|
+
const payload = request.payload;
|
|
288
|
+
switch (request.operation) {
|
|
289
|
+
case "capabilities":
|
|
290
|
+
return success(request, await client.getCapabilities());
|
|
291
|
+
case "apply":
|
|
292
|
+
return success(
|
|
293
|
+
request,
|
|
294
|
+
await client.apply(
|
|
295
|
+
requirePayload(payload, "resource"),
|
|
296
|
+
payload.options
|
|
297
|
+
)
|
|
298
|
+
);
|
|
299
|
+
case "get":
|
|
300
|
+
return success(
|
|
301
|
+
request,
|
|
302
|
+
await client.get(
|
|
303
|
+
requirePayload(payload, "reference"),
|
|
304
|
+
payload.options
|
|
305
|
+
)
|
|
306
|
+
);
|
|
307
|
+
case "list":
|
|
308
|
+
return success(
|
|
309
|
+
request,
|
|
310
|
+
await client.list(
|
|
311
|
+
requirePayload(payload, "query"),
|
|
312
|
+
payload.options
|
|
313
|
+
)
|
|
314
|
+
);
|
|
315
|
+
case "delete":
|
|
316
|
+
return success(
|
|
317
|
+
request,
|
|
318
|
+
await client.delete(
|
|
319
|
+
requirePayload(payload, "reference"),
|
|
320
|
+
payload.options
|
|
321
|
+
)
|
|
322
|
+
);
|
|
323
|
+
case "watch":
|
|
324
|
+
throw new OrchestrationError({
|
|
325
|
+
code: "INVALID",
|
|
326
|
+
message: "watch requests require the streaming protocol method",
|
|
327
|
+
retryable: false
|
|
328
|
+
});
|
|
329
|
+
default:
|
|
330
|
+
throw new OrchestrationError({
|
|
331
|
+
code: "UNSUPPORTED",
|
|
332
|
+
message: `unsupported remote orchestration operation '${String(request.operation)}'`,
|
|
333
|
+
retryable: false
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
} catch (error) {
|
|
337
|
+
return failure(request, error);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
async *watch(request, options = {}) {
|
|
341
|
+
try {
|
|
342
|
+
validate(request);
|
|
343
|
+
if (request.operation !== "watch") {
|
|
344
|
+
throw new OrchestrationError({
|
|
345
|
+
code: "INVALID",
|
|
346
|
+
message: "streaming protocol accepts only watch operations",
|
|
347
|
+
retryable: false
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
const watchOptions = request.payload.options;
|
|
351
|
+
for await (const event of client.watch(
|
|
352
|
+
requirePayload(request.payload, "query"),
|
|
353
|
+
{
|
|
354
|
+
...watchOptions,
|
|
355
|
+
signal: options.signal
|
|
356
|
+
}
|
|
357
|
+
)) {
|
|
358
|
+
yield success(request, event);
|
|
359
|
+
}
|
|
360
|
+
} catch (error) {
|
|
361
|
+
yield failure(request, error);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function createFetchOrchestrationTransport(options) {
|
|
367
|
+
const fetch_ = options.fetch ?? globalThis.fetch;
|
|
368
|
+
const maxResponseBytes = options.maxResponseBytes ?? 1024 * 1024;
|
|
369
|
+
const maxWatchLineBytes = options.maxWatchLineBytes ?? 1024 * 1024;
|
|
370
|
+
function assertWatchLineSize(line) {
|
|
371
|
+
if (new TextEncoder().encode(line).byteLength > maxWatchLineBytes) {
|
|
372
|
+
throw new OrchestrationError({
|
|
373
|
+
code: "EXHAUSTED",
|
|
374
|
+
message: `remote orchestration watch line exceeds ${maxWatchLineBytes} bytes`,
|
|
375
|
+
retryable: false
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
async function headers(accept) {
|
|
380
|
+
const additional = typeof options.headers === "function" ? await options.headers() : options.headers ?? {};
|
|
381
|
+
return {
|
|
382
|
+
Accept: accept,
|
|
383
|
+
"Content-Type": "application/json",
|
|
384
|
+
...additional
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
async function post(request, accept, signal) {
|
|
388
|
+
const response = await fetch_(options.endpoint, {
|
|
389
|
+
method: "POST",
|
|
390
|
+
headers: await headers(accept),
|
|
391
|
+
body: JSON.stringify(request),
|
|
392
|
+
signal,
|
|
393
|
+
...options.credentials ? { credentials: options.credentials } : {}
|
|
394
|
+
});
|
|
395
|
+
if (!response.ok) {
|
|
396
|
+
throw new OrchestrationError({
|
|
397
|
+
code: response.status === 401 || response.status === 403 ? "FORBIDDEN" : "UNAVAILABLE",
|
|
398
|
+
message: `remote orchestration endpoint returned HTTP ${response.status}`,
|
|
399
|
+
retryable: response.status >= 500
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
return response;
|
|
403
|
+
}
|
|
404
|
+
async function readBoundedText(response, limit) {
|
|
405
|
+
if (!response.body) return "";
|
|
406
|
+
const reader = response.body.getReader();
|
|
407
|
+
const decoder = new TextDecoder();
|
|
408
|
+
let size = 0;
|
|
409
|
+
let text = "";
|
|
410
|
+
try {
|
|
411
|
+
for (; ; ) {
|
|
412
|
+
const { done, value } = await reader.read();
|
|
413
|
+
if (done) break;
|
|
414
|
+
size += value.byteLength;
|
|
415
|
+
if (size > limit) {
|
|
416
|
+
await reader.cancel();
|
|
417
|
+
throw new OrchestrationError({
|
|
418
|
+
code: "EXHAUSTED",
|
|
419
|
+
message: `remote orchestration response exceeds ${limit} bytes`,
|
|
420
|
+
retryable: false
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
text += decoder.decode(value, { stream: true });
|
|
424
|
+
}
|
|
425
|
+
return text + decoder.decode();
|
|
426
|
+
} finally {
|
|
427
|
+
reader.releaseLock();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
async request(request, transportOptions = {}) {
|
|
432
|
+
const response = await post(request, "application/json", transportOptions.signal);
|
|
433
|
+
const text = await readBoundedText(response, maxResponseBytes);
|
|
434
|
+
return JSON.parse(text);
|
|
435
|
+
},
|
|
436
|
+
async *watch(request, transportOptions = {}) {
|
|
437
|
+
const response = await post(request, "application/x-ndjson", transportOptions.signal);
|
|
438
|
+
if (!response.body) {
|
|
439
|
+
throw new OrchestrationError({
|
|
440
|
+
code: "UNAVAILABLE",
|
|
441
|
+
message: "remote orchestration watch response has no body",
|
|
442
|
+
retryable: true
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
const reader = response.body.getReader();
|
|
446
|
+
const decoder = new TextDecoder();
|
|
447
|
+
let pending = "";
|
|
448
|
+
let streamCompleted = false;
|
|
449
|
+
try {
|
|
450
|
+
for (; ; ) {
|
|
451
|
+
const { done, value } = await reader.read();
|
|
452
|
+
if (done) {
|
|
453
|
+
streamCompleted = true;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
pending += decoder.decode(value, { stream: true });
|
|
457
|
+
let newline = pending.indexOf("\n");
|
|
458
|
+
while (newline >= 0) {
|
|
459
|
+
const line = pending.slice(0, newline).trim();
|
|
460
|
+
pending = pending.slice(newline + 1);
|
|
461
|
+
assertWatchLineSize(line);
|
|
462
|
+
if (line) yield JSON.parse(line);
|
|
463
|
+
newline = pending.indexOf("\n");
|
|
464
|
+
}
|
|
465
|
+
if (pending.length > maxWatchLineBytes) {
|
|
466
|
+
throw new OrchestrationError({
|
|
467
|
+
code: "EXHAUSTED",
|
|
468
|
+
message: `remote orchestration watch line exceeds ${maxWatchLineBytes} bytes`,
|
|
469
|
+
retryable: false
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
pending += decoder.decode();
|
|
474
|
+
if (pending.trim()) {
|
|
475
|
+
assertWatchLineSize(pending.trim());
|
|
476
|
+
yield JSON.parse(pending);
|
|
477
|
+
}
|
|
478
|
+
} finally {
|
|
479
|
+
if (!streamCompleted) {
|
|
480
|
+
await reader.cancel().catch(() => void 0);
|
|
481
|
+
}
|
|
482
|
+
reader.releaseLock();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export {
|
|
489
|
+
REMOTE_ORCHESTRATION_PROTOCOL,
|
|
490
|
+
createRemoteOrchestrationClient,
|
|
491
|
+
createReadOnlyOrchestrationClient,
|
|
492
|
+
createNamespacedOrchestrationClient,
|
|
493
|
+
createRemoteOrchestrationHandler,
|
|
494
|
+
createFetchOrchestrationTransport
|
|
495
|
+
};
|
|
496
|
+
//# sourceMappingURL=chunk-CCEFAOSH.js.map
|