@constal/sdk 3.0.1 → 3.2.0
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/package.json +1 -1
- package/publish/api.json +3 -1
- package/publish/index.d.ts +115 -87
- package/publish/index.js +358 -232
package/package.json
CHANGED
package/publish/api.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"package": "@constal/sdk",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"exports": [
|
|
5
5
|
"Action",
|
|
6
6
|
"ActionPattern",
|
|
@@ -296,6 +296,7 @@
|
|
|
296
296
|
"SetupAction",
|
|
297
297
|
"SetupCredentialCandidate",
|
|
298
298
|
"SetupCredentialInteractionPanel",
|
|
299
|
+
"SetupCredentialReceipt",
|
|
299
300
|
"SetupFormPanel",
|
|
300
301
|
"SetupPanel",
|
|
301
302
|
"SetupProgressPanel",
|
|
@@ -463,6 +464,7 @@
|
|
|
463
464
|
"scorerName",
|
|
464
465
|
"selectableResourceLabels",
|
|
465
466
|
"setupAwait",
|
|
467
|
+
"setupCredentialReceipt",
|
|
466
468
|
"setupScreen",
|
|
467
469
|
"setupScreenView",
|
|
468
470
|
"setupSubmission",
|
package/publish/index.d.ts
CHANGED
|
@@ -586,6 +586,89 @@ declare function renderTrainingCompletion(input: unknown, expected?: unknown): {
|
|
|
586
586
|
completion: string | null;
|
|
587
587
|
};
|
|
588
588
|
|
|
589
|
+
/** Stable capability shared by configured Models and directly bound Gateways. */
|
|
590
|
+
declare const MODEL_COMPLETION_CAPABILITY: CapabilityContractRef;
|
|
591
|
+
type ModelGatewayProtocol = "anthropic" | "openai";
|
|
592
|
+
type RawModelProtocol = ModelGatewayProtocol | "bedrock";
|
|
593
|
+
/** Optional generation choices. Supported effort values are defined by the selected model. */
|
|
594
|
+
interface ModelGenerationOptions {
|
|
595
|
+
maxOutputTokens?: number;
|
|
596
|
+
temperature?: number;
|
|
597
|
+
effort?: string;
|
|
598
|
+
}
|
|
599
|
+
interface ModelTool {
|
|
600
|
+
name: string;
|
|
601
|
+
version?: string;
|
|
602
|
+
description: string;
|
|
603
|
+
schema: object;
|
|
604
|
+
}
|
|
605
|
+
interface ModelInvocationArgs extends ModelGenerationOptions {
|
|
606
|
+
/** Logical Model identity or a model selected through a bound Gateway, evaluated under Policy. */
|
|
607
|
+
model?: string;
|
|
608
|
+
system?: string;
|
|
609
|
+
objective?: unknown;
|
|
610
|
+
context?: unknown;
|
|
611
|
+
tools?: ModelTool[];
|
|
612
|
+
/** Constrain whether an offered Tool must be selected for this generation. */
|
|
613
|
+
toolChoice?: "auto" | "required";
|
|
614
|
+
feedback?: string[];
|
|
615
|
+
stream?: boolean;
|
|
616
|
+
/** Host-adapter escape hatch for a qualified upstream SDK wire request. Credentials and the selected model remain platform-owned. */
|
|
617
|
+
rawProtocol?: {
|
|
618
|
+
protocol: RawModelProtocol;
|
|
619
|
+
request: Record<string, unknown>;
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
interface ModelCredentialHeader {
|
|
623
|
+
slot: string;
|
|
624
|
+
header: string;
|
|
625
|
+
scheme: "bearer" | "raw";
|
|
626
|
+
}
|
|
627
|
+
interface ModelGatewayConfig {
|
|
628
|
+
baseUrl: string;
|
|
629
|
+
protocol: ModelGatewayProtocol;
|
|
630
|
+
model: string;
|
|
631
|
+
maxOutputTokens?: number;
|
|
632
|
+
temperature?: number;
|
|
633
|
+
gatewayAuth?: ModelCredentialHeader | null;
|
|
634
|
+
providerAuth?: ModelCredentialHeader | null;
|
|
635
|
+
}
|
|
636
|
+
type NormalizedModelGatewayConfig = Omit<ModelGatewayConfig, "maxOutputTokens" | "temperature" | "gatewayAuth" | "providerAuth"> & {
|
|
637
|
+
maxOutputTokens: number;
|
|
638
|
+
temperature: number | null;
|
|
639
|
+
gatewayAuth: ModelCredentialHeader | null;
|
|
640
|
+
providerAuth: ModelCredentialHeader | null;
|
|
641
|
+
};
|
|
642
|
+
interface ModelInvocationResult {
|
|
643
|
+
content: string;
|
|
644
|
+
toolCalls?: {
|
|
645
|
+
id: string;
|
|
646
|
+
name: string;
|
|
647
|
+
args: unknown;
|
|
648
|
+
}[];
|
|
649
|
+
/** Integration-observed timing for the complete upstream model request. */
|
|
650
|
+
timing?: {
|
|
651
|
+
upstreamMs: number;
|
|
652
|
+
};
|
|
653
|
+
usage: {
|
|
654
|
+
input: number;
|
|
655
|
+
output: number;
|
|
656
|
+
cached: number;
|
|
657
|
+
cacheWrite?: number;
|
|
658
|
+
/** Exact upstream inference cost when the Gateway can establish it; null means unavailable. */
|
|
659
|
+
costUsd?: number | null;
|
|
660
|
+
costSource?: string;
|
|
661
|
+
costEstimated?: boolean;
|
|
662
|
+
};
|
|
663
|
+
provider: string;
|
|
664
|
+
model: string;
|
|
665
|
+
}
|
|
666
|
+
declare function normalizeModelGatewayConfig(value: unknown): NormalizedModelGatewayConfig;
|
|
667
|
+
declare function modelGatewayEndpoint(config: Pick<ModelGatewayConfig, "baseUrl" | "protocol">): URL;
|
|
668
|
+
declare function modelPrompt(args: ModelInvocationArgs): string;
|
|
669
|
+
declare function modelProtocolRequest(protocol: ModelGatewayProtocol, model: string, maxOutputTokens: number, temperature: number | null, args: ModelInvocationArgs): Record<string, unknown>;
|
|
670
|
+
declare function modelProtocolResult(protocol: ModelGatewayProtocol, raw: unknown, provider: string, model: string): ModelInvocationResult;
|
|
671
|
+
|
|
589
672
|
interface GatewayCredentialSlotSetup {
|
|
590
673
|
title: string;
|
|
591
674
|
description?: string;
|
|
@@ -716,8 +799,6 @@ declare function gateway<C>(definition: GatewayDefinition<C>): GatewayPackage<C>
|
|
|
716
799
|
* other Resource.
|
|
717
800
|
*/
|
|
718
801
|
declare function trainingProvider<C>(definition: TrainingProviderDefinition<C>): GatewayPackage<C>;
|
|
719
|
-
/** Stable capability implemented by every model-completion Gateway. */
|
|
720
|
-
declare const MODEL_COMPLETION_CAPABILITY: CapabilityContractRef;
|
|
721
802
|
/** Stable capability implemented by Gateways that import immutable training checkpoints. */
|
|
722
803
|
declare const MODEL_CHECKPOINT_IMPORT_CAPABILITY: CapabilityContractRef;
|
|
723
804
|
/** Stable capability implemented by remote MCP client Gateways. */
|
|
@@ -1199,8 +1280,8 @@ type ModelGovernanceMeter = "cached_input_tokens" | "input_tokens" | "output_tok
|
|
|
1199
1280
|
type UiGovernanceMeter = "requests";
|
|
1200
1281
|
declare function sandboxControls(values: Partial<SandboxGovernanceControls>): ResourceControlsConstraint;
|
|
1201
1282
|
declare function sandboxLimit(input: AdmissionLimitInput<SandboxGovernanceMeter>): AdmissionLimitConstraint;
|
|
1202
|
-
declare function modelControls(values: Partial<ModelGovernanceControls
|
|
1203
|
-
declare function modelLimit(input: AdmissionLimitInput<ModelGovernanceMeter
|
|
1283
|
+
declare function modelControls(values: Partial<ModelGovernanceControls>, contract?: GovernanceContractRef): ResourceControlsConstraint;
|
|
1284
|
+
declare function modelLimit(input: AdmissionLimitInput<ModelGovernanceMeter>, contract?: GovernanceContractRef): AdmissionLimitConstraint;
|
|
1204
1285
|
declare function uiLimit(input: AdmissionLimitInput<UiGovernanceMeter>): AdmissionLimitConstraint;
|
|
1205
1286
|
|
|
1206
1287
|
type PrincipalKind = "user" | "service" | "channel" | "agent" | "anonymous";
|
|
@@ -1790,7 +1871,7 @@ interface TurnGate {
|
|
|
1790
1871
|
feedback?(rec: TurnRecord | TurnDraft): string;
|
|
1791
1872
|
onExhausted?: "fail" | "commit-with-verdict";
|
|
1792
1873
|
}
|
|
1793
|
-
interface TurnSpec {
|
|
1874
|
+
interface TurnSpec extends ModelGenerationOptions {
|
|
1794
1875
|
system: string;
|
|
1795
1876
|
objective?: unknown;
|
|
1796
1877
|
context?: unknown;
|
|
@@ -1798,10 +1879,11 @@ interface TurnSpec {
|
|
|
1798
1879
|
/** Require one of the offered Tools for this model generation. */
|
|
1799
1880
|
toolChoice?: "auto" | "required";
|
|
1800
1881
|
gate?: TurnGate;
|
|
1882
|
+
/** Model binding name; when gateway is supplied, the Gateway's model identifier instead. */
|
|
1801
1883
|
model?: string;
|
|
1884
|
+
/** Bound Gateway to use with the explicitly selected model identifier. */
|
|
1885
|
+
gateway?: string;
|
|
1802
1886
|
stream?: boolean;
|
|
1803
|
-
/** Requested output ceiling for this turn. The bound Model and Policy may lower it. */
|
|
1804
|
-
maxOutputTokens?: number;
|
|
1805
1887
|
}
|
|
1806
1888
|
interface ToolCallRecord {
|
|
1807
1889
|
id: string;
|
|
@@ -2097,8 +2179,9 @@ declare function validateTool(tool: Tool, path?: string): Tool;
|
|
|
2097
2179
|
declare function validateView<V extends ViewDef<any, any>>(view: V, path?: string): V;
|
|
2098
2180
|
declare function validatePartitionFn<I, O, R>(fn: PartitionFn<I, O, R>): PartitionFn<I, O, R>;
|
|
2099
2181
|
declare function validateFoldFn<I, O>(fn: FoldFn<I, O> | SqlFold): FoldFn<I, O> | SqlFold;
|
|
2100
|
-
declare function agent<S>(input: Omit<AgentDef<S>, "version"> & {
|
|
2182
|
+
declare function agent<S>(input: Omit<AgentDef<S>, "version" | "model"> & {
|
|
2101
2183
|
version?: string;
|
|
2184
|
+
model?: string;
|
|
2102
2185
|
}): AgentDef<S>;
|
|
2103
2186
|
declare function subtask<T>(def: Task<T>): Task<T>;
|
|
2104
2187
|
|
|
@@ -2412,6 +2495,26 @@ interface SetupCredentialInteractionPanel extends SetupPanelBase {
|
|
|
2412
2495
|
provider: string;
|
|
2413
2496
|
credentialId: string;
|
|
2414
2497
|
operation: "connect" | "reauthorize" | "manage";
|
|
2498
|
+
/** Opt into the generic completion contract; omission preserves existing screens. */
|
|
2499
|
+
receipt?: "reference" | "evidence";
|
|
2500
|
+
/** Reuse/save a choice through the ordinary scoped Credential binding API. */
|
|
2501
|
+
selection?: Pick<AgentCredentialSetupRequirement, "selector" | "binding">;
|
|
2502
|
+
/** Non-secret creation configuration, validated by the Credential Provider. */
|
|
2503
|
+
configuration?: Record<string, unknown>;
|
|
2504
|
+
}
|
|
2505
|
+
interface SetupCredentialReceipt {
|
|
2506
|
+
object: "constal.setup.credential";
|
|
2507
|
+
version: 1;
|
|
2508
|
+
credential: {
|
|
2509
|
+
crn: string;
|
|
2510
|
+
hash: string;
|
|
2511
|
+
};
|
|
2512
|
+
evidence: CredentialEvidence | null;
|
|
2513
|
+
binding: {
|
|
2514
|
+
crn: string;
|
|
2515
|
+
headSeq: number;
|
|
2516
|
+
revisionHash: string;
|
|
2517
|
+
} | null;
|
|
2415
2518
|
}
|
|
2416
2519
|
interface SetupReviewPanel extends SetupPanelBase {
|
|
2417
2520
|
kind: "review";
|
|
@@ -2472,6 +2575,8 @@ interface SetupSubmission {
|
|
|
2472
2575
|
declare function setupScreen(value: unknown): SetupScreen;
|
|
2473
2576
|
/** Validates one response against the exact open screen revision and form schema. */
|
|
2474
2577
|
declare function setupSubmission(value: unknown, screen: SetupScreen): SetupSubmission;
|
|
2578
|
+
/** Validate non-secret completion data. It is a snapshot, never a grant of authority. */
|
|
2579
|
+
declare function setupCredentialReceipt(value: unknown, panel: SetupCredentialInteractionPanel): SetupCredentialReceipt;
|
|
2475
2580
|
/** Await options for the exact screen. Runtime wait resolution remains the authority and replay fence. */
|
|
2476
2581
|
declare function setupAwait(screen: SetupScreen): AwaitOpts<SetupSubmission>;
|
|
2477
2582
|
/** A deterministic latest-screen projection for Console discovery and reload. */
|
|
@@ -3600,83 +3705,6 @@ declare function credentialProviderSetupMetadata(value: unknown, slots: string[]
|
|
|
3600
3705
|
/** Defines and validates a Credential Provider package. */
|
|
3601
3706
|
declare function credentialProvider<C>(definition: CredentialProviderDefinition<C>): CredentialProviderPackage<C>;
|
|
3602
3707
|
|
|
3603
|
-
type ModelGatewayProtocol = "anthropic" | "openai";
|
|
3604
|
-
type RawModelProtocol = ModelGatewayProtocol | "bedrock";
|
|
3605
|
-
interface ModelTool {
|
|
3606
|
-
name: string;
|
|
3607
|
-
version?: string;
|
|
3608
|
-
description: string;
|
|
3609
|
-
schema: object;
|
|
3610
|
-
}
|
|
3611
|
-
interface ModelInvocationArgs {
|
|
3612
|
-
/** Admission-pinned logical model. Runtime code cannot override this value. */
|
|
3613
|
-
model?: string;
|
|
3614
|
-
system?: string;
|
|
3615
|
-
objective?: unknown;
|
|
3616
|
-
context?: unknown;
|
|
3617
|
-
tools?: ModelTool[];
|
|
3618
|
-
/** Constrain whether an offered Tool must be selected for this generation. */
|
|
3619
|
-
toolChoice?: "auto" | "required";
|
|
3620
|
-
feedback?: string[];
|
|
3621
|
-
maxOutputTokens?: number;
|
|
3622
|
-
temperature?: number;
|
|
3623
|
-
stream?: boolean;
|
|
3624
|
-
/** Host-adapter escape hatch for a qualified upstream SDK wire request. Credentials and the selected model remain platform-owned. */
|
|
3625
|
-
rawProtocol?: {
|
|
3626
|
-
protocol: RawModelProtocol;
|
|
3627
|
-
request: Record<string, unknown>;
|
|
3628
|
-
};
|
|
3629
|
-
}
|
|
3630
|
-
interface ModelCredentialHeader {
|
|
3631
|
-
slot: string;
|
|
3632
|
-
header: string;
|
|
3633
|
-
scheme: "bearer" | "raw";
|
|
3634
|
-
}
|
|
3635
|
-
interface ModelGatewayConfig {
|
|
3636
|
-
baseUrl: string;
|
|
3637
|
-
protocol: ModelGatewayProtocol;
|
|
3638
|
-
model: string;
|
|
3639
|
-
maxOutputTokens?: number;
|
|
3640
|
-
temperature?: number;
|
|
3641
|
-
gatewayAuth?: ModelCredentialHeader | null;
|
|
3642
|
-
providerAuth?: ModelCredentialHeader | null;
|
|
3643
|
-
}
|
|
3644
|
-
type NormalizedModelGatewayConfig = Omit<ModelGatewayConfig, "maxOutputTokens" | "temperature" | "gatewayAuth" | "providerAuth"> & {
|
|
3645
|
-
maxOutputTokens: number;
|
|
3646
|
-
temperature: number | null;
|
|
3647
|
-
gatewayAuth: ModelCredentialHeader | null;
|
|
3648
|
-
providerAuth: ModelCredentialHeader | null;
|
|
3649
|
-
};
|
|
3650
|
-
interface ModelInvocationResult {
|
|
3651
|
-
content: string;
|
|
3652
|
-
toolCalls?: {
|
|
3653
|
-
id: string;
|
|
3654
|
-
name: string;
|
|
3655
|
-
args: unknown;
|
|
3656
|
-
}[];
|
|
3657
|
-
/** Integration-observed timing for the complete upstream model request. */
|
|
3658
|
-
timing?: {
|
|
3659
|
-
upstreamMs: number;
|
|
3660
|
-
};
|
|
3661
|
-
usage: {
|
|
3662
|
-
input: number;
|
|
3663
|
-
output: number;
|
|
3664
|
-
cached: number;
|
|
3665
|
-
cacheWrite?: number;
|
|
3666
|
-
/** Exact upstream inference cost when the Gateway can establish it; null means unavailable. */
|
|
3667
|
-
costUsd?: number | null;
|
|
3668
|
-
costSource?: string;
|
|
3669
|
-
costEstimated?: boolean;
|
|
3670
|
-
};
|
|
3671
|
-
provider: string;
|
|
3672
|
-
model: string;
|
|
3673
|
-
}
|
|
3674
|
-
declare function normalizeModelGatewayConfig(value: unknown): NormalizedModelGatewayConfig;
|
|
3675
|
-
declare function modelGatewayEndpoint(config: Pick<ModelGatewayConfig, "baseUrl" | "protocol">): URL;
|
|
3676
|
-
declare function modelPrompt(args: ModelInvocationArgs): string;
|
|
3677
|
-
declare function modelProtocolRequest(protocol: ModelGatewayProtocol, model: string, maxOutputTokens: number, temperature: number | null, args: ModelInvocationArgs): Record<string, unknown>;
|
|
3678
|
-
declare function modelProtocolResult(protocol: ModelGatewayProtocol, raw: unknown, provider: string, model: string): ModelInvocationResult;
|
|
3679
|
-
|
|
3680
3708
|
type CodeScorerRule = {
|
|
3681
3709
|
op: "all";
|
|
3682
3710
|
rules: CodeScorerRule[];
|
|
@@ -3842,5 +3870,5 @@ declare class SessionDeleted extends Error {
|
|
|
3842
3870
|
constructor(session: string);
|
|
3843
3871
|
}
|
|
3844
3872
|
|
|
3845
|
-
export { AfterYield, ApiError, CONSTAL_API_CAPABILITY, CONSTAL_API_GET_KINDS, CONSTAL_API_MODEL_TOOL_DESCRIPTIONS, CONSTAL_API_OPERATIONS, CONSTAL_API_OPERATION_SCHEMAS, CONSTAL_API_QUERY_KINDS, CONSTAL_API_VERSION, CommitConflict, CommitGateRejected, CredentialRevoked, CredentialUnavailable, DirectNetworkDenied, EffectCeilingExceeded, GateExhausted, IntegrationRequestNotSent, LeaseLost, MCP_CLIENT_CAPABILITY, MEMORY_OPERATION_DECLARATIONS, MODEL_CHECKPOINT_IMPORT_CAPABILITY, MODEL_COMPLETION_CAPABILITY, NondeterministicReplay, OutcomeUnknown, PolicyConstraintFailed, PolicyDecisionFailed, RESOURCE_KINDS, ResourceDisabled, ResourceInvalid, ResourceUnbound, RollbackTargetInvalid, SessionDeleted, SpawnCardinality, SwallowedYield, TRAINING_PROVIDER_CAPABILITY, TerminalIntegrationFailure, ToolUnavailable, UI_BUNDLE_BOUNDS, UnknownTool, WEB_FETCH_ARGUMENT_SCHEMA, WEB_SEARCH_ARGUMENT_SCHEMA, action, actionPattern, agent, agentResourceBinding, agentSetupMetadata, agentSetupRequirements, analyticsEvent, approximateTokens, authProvider, authProviderName, bindingName, bucketFor, canonicalJson, capabilityContractRef, casTool, channel, channelIngressRequest, channelIngressSource, channelSourceEvidence, channelSubscriptionRequest, channelTarget, checkpointArtifactRef, checkpointDeploymentRequest, checkpointImportMetadata, checkpointImportRequest, codeScorerIR, credentialEvidence, credentialInteractionAction, credentialInteractionEvent, credentialInteractionResult, credentialName, credentialProvider, credentialProviderConfigSchema, credentialProviderName, credentialProviderSetupMetadata, credentialRotationDefaults, credentialSetupState, customerTenantName, cutBatches, cutPartitions, datasetName, evaluateCodeScorer, evaluatePolicyDefinition, gateway, gatewayModelOffer, gatewayPackageMetadata, hash, hashValue, integrationEgressPolicy, labelSelector, matchesAction, matchesLabelSelector, matchesResource, memoryStoreBinding, modelAdvertisedPricing, modelControls, modelGatewayBinding, modelGatewayEndpoint, modelLimit, modelPrompt, modelProtocolRequest, modelProtocolResult, murmur3_32, normalizeModelGatewayConfig, normalizeSandboxNetworkPolicy, opTool, opTools, parseResourceName, policy, policyName, renderTrainingCompletion, resolveBindingOwner, resolveGatewayEgress, resolveResourceDependencyRef, resourceContractRef, resourceCredentialBinding, resourceDependencyRef, resourceLabelMap, resourceName, resourceNeed, resourcePattern, resourceSelector, sandboxControls, sandboxLimit, scopedBindingKey, scopedCredentialRef, scopedResourceRef, scorerName, selectableResourceLabels, setupAwait, setupScreen, setupScreenView, setupSubmission, sha256Hex, stageOutput, startTrainingRequest, subtask, tableDescribe, tableQuery, trainingProvider, trainingProviderMetadata, trainingRecipe, uiBundle, uiBundleManifest, uiLimit, uiName, validateBatchSpec, validateFoldFn, validateJsonSchema, validateJsonSchemaDefinition, validatePartitionFn, validatePartitionSpec, validateStageOutputSpec, validateTool, validateView, webFetch, webSearch };
|
|
3846
|
-
export type { Action, ActionPattern, Actor, AdmissionLimitConstraint, AdmissionLimitInput, AdmissionLimitScope, AdmissionLimitWindow, Agent, AgentCredentialSetupRequirement, AgentDef, AgentDeployPolicy, AgentSetupMetadata, AgentSetupRequirement, AgentSetupWorkflow, AnalyticsClient, AnalyticsDimensionValue, AnalyticsEventDefinition, AnalyticsIntent, AnalyticsValues, AuthProvider, AuthProviderCRN, AuthProviderContext, AuthProviderRequest, AuthProviderResult, AwaitOpts, AwaitPresentation, BatchSpec, BindingCRN, BindingOwnerContext, BindingOwnerScope, BranchRef, CRN, CRNKind, CanonicalEvent, CanonicalEventDraft, CapabilityContractRef, CapabilityGrant, CapabilityRef, CaptureCaseRequest, CaseRow, CatalogTool, Channel, ChannelAlarm, ChannelAlarmResult, ChannelContext, ChannelIngressEvent, ChannelIngressSource, ChannelMessage, ChannelProtocol, ChannelReceiveResult, ChannelRequest, ChannelResponse, ChannelSourceEvidence, ChannelSubscriptionRequest, ChannelTarget, CheckpointDeploymentRequest, CheckpointImportMetadata, CheckpointImportRequest, CodeScoreResult, CodeScorerIR, CodeScorerRule, CommitOpts, CompareSuitesRequest, Compensation, ConnectionCancelRequest, ConnectionIdentity, ConnectionOperation, ConnectionRecoveryRequest, ConnectionRecoveryResult, ConnectionRequest, ConnectionUsageReport, ConstalApiApplyRequest, ConstalApiChangePlan, ConstalApiChangePlanRef, ConstalApiChangePlanRequest, ConstalApiChangeReceipt, ConstalApiOperationReceipt, ControlEvent, Cost, CreateSandboxImageOptions, CreateSandboxOptions, CredentialCRN, CredentialDestroyResult, CredentialEvidence, CredentialInteractionAction, CredentialInteractionAdvanceRequest, CredentialInteractionEvent, CredentialInteractionPrimaryAction, CredentialInteractionProof, CredentialInteractionResult, CredentialInteractionStartRequest, CredentialMaterialRequest, CredentialMintRequest, CredentialMintResult, CredentialProviderCRN, CredentialProviderContext, CredentialProviderCredentialSlotSetup, CredentialProviderDefinition, CredentialProviderPackage, CredentialProviderPackageMetadata, CredentialProviderSecretInput, CredentialProviderSetupMetadata, CredentialSetupState, CredentialVerifyResult, Ctx, CustomerTenantCRN, DataManifest, DatasetCRN, DatasetDraft, DatasetRef, DelegatedGrant, DelegationCeiling, DeliveryMode, DeliveryReceipt, DispatchResult, EffectClass, EvalComparison, EvalDivergence, EvalMode, EvalSubject, EvalSubjectSource, EventBase, Fact, FactRef, FileEntry, FixedMemoryStoreRef, FixedModelGatewayRef, FoldFn, GateEvidence, GateResult, GateVerdict, GatewayCancelRequest, GatewayConfigEgressBinding, GatewayContext, GatewayCredentialSlotSetup, GatewayDefinition, GatewayDiscoverySetup, GatewayModelOffer, GatewayOperation, GatewayPackage, GatewayPackageMetadata, GatewayRecoveryRequest, GatewayRecoveryResult, GatewayRequest, GovernanceContractRef, Handle, HandleOutcome, Hash, HistoryView, IgnoredChannelEvent, IngressRequest, IngressTarget, IntegrationArtifactEgressRequest, IntegrationArtifactEgressResponse, IntegrationContext, IntegrationEgressPolicy, IntegrationEgressRequest, IntegrationEgressResponse, IntegrationEgressRule, IntegrationSecret, IntegrationState, InvokableKind, InvokeOpts, JsonScalar, JsonValue, LabelRequest, LabelSelector, LabelSelectorOperator, LabelSelectorRequirement, LedgerAddress, LedgerEvent, LocalResourceRef, ManifestIndexPage, MapFact, MapOpts, MemoryDeleteArgs, MemoryGetArgs, MemoryRecord, MemoryRememberArgs, MemorySearchArgs, MemorySearchHit, MemoryStoreBinding, Mode, ModelAdvertisedPricing, ModelCredentialHeader, ModelGatewayBinding, ModelGatewayConfig, ModelGatewayProtocol, ModelGovernanceControls, ModelGovernanceMeter, ModelInvocationArgs, ModelInvocationResult, ModelTechnicalCapabilities, ModelTool, NormalizedModelGatewayConfig, Out, Over, PartitionFn, PartitionSpec, Partitioning, PolicyCRN, PolicyConstraint, PolicyContextValue, PolicyDefinition, PolicyInput, PolicyInvocationOrigin, PolicyOutcome, Principal, PrincipalKind, Provenance, RawModelProtocol, Recovery, ReduceFact, ReduceOpts, Ref, RequestLabelRequest, ResourceContractRef, ResourceControlsConstraint, ResourceCredentialBinding, ResourceDependencyRef, ResourceKind, ResourceName, ResourceNameParts, ResourceNeed, ResourcePattern, ResourceSelector, RollbackReport, RunIdentityView, RunInfo, RunStatusDetail, RunSuiteRequest, Sandbox, SandboxCommandResult, SandboxExecInput, SandboxFileResult, SandboxGovernanceControls, SandboxGovernanceMeter, SandboxImage, SandboxMutationResult, SandboxNetworkMode, SandboxNetworkPolicy, SandboxPool, SandboxReadFileOptions, SandboxReadFileResult, SandboxWriteFileResult, ScopedBindingKey, ScopedCredentialRef, ScopedMemoryStoreRef, ScopedModelGatewayRef, ScopedResourceRef, ScoreRequest, ScorerApplies, ScorerCRN, ScorerDef, ScorerEvaluation, ScorerKind, ScorerRef, ScorerVerdictIntent, SetEvalBaselineRequest, SetupAction, SetupCredentialCandidate, SetupCredentialInteractionPanel, SetupFormPanel, SetupPanel, SetupProgressPanel, SetupReviewPanel, SetupScreen, SetupStepStatus, SetupStepSummary, SetupSubmission, SetupTerminalPanel, SetupWorkflowStatus, SortField, SpawnAttenuation, SpawnBudget, SpawnOpts, SqlFold, StageInfo, StageOutputSpec, StartTrainingRequest, SteerEvent, SuiteFact, TableAggregate, TableDescribeArgs, TableFilter, TableFilterOperation, TableOrder, TableQueryArgs, TableQueryPlan, TableQueryResult, TableScalar, TableSnapshotDescription, Task, Tier, Tool, ToolCallRecord, TrainingJobFact, TrainingJobReference, TrainingJobState, TrainingJobStatus, TrainingMethod, TrainingModelOffer, TrainingProviderDefinition, TrainingProviderMetadata, TrainingProviderPin, TrainingRecipe, TrainingResumePoint, TrainingUsageUnits, TurnDraft, TurnGate, TurnRecord, TurnSpec, UiAccess, UiBundle, UiBundleManifest, UiCRN, UiCapability, UiExecution, UiGovernanceMeter, UiHandler, UiResource, UiRuntimeContext, UiSource, UiSqlResult, UiState, UpstreamPayer, Verdict, VerdictSamplingMode, ViewDef, WaitResolvedEvent };
|
|
3873
|
+
export { AfterYield, ApiError, CONSTAL_API_CAPABILITY, CONSTAL_API_GET_KINDS, CONSTAL_API_MODEL_TOOL_DESCRIPTIONS, CONSTAL_API_OPERATIONS, CONSTAL_API_OPERATION_SCHEMAS, CONSTAL_API_QUERY_KINDS, CONSTAL_API_VERSION, CommitConflict, CommitGateRejected, CredentialRevoked, CredentialUnavailable, DirectNetworkDenied, EffectCeilingExceeded, GateExhausted, IntegrationRequestNotSent, LeaseLost, MCP_CLIENT_CAPABILITY, MEMORY_OPERATION_DECLARATIONS, MODEL_CHECKPOINT_IMPORT_CAPABILITY, MODEL_COMPLETION_CAPABILITY, NondeterministicReplay, OutcomeUnknown, PolicyConstraintFailed, PolicyDecisionFailed, RESOURCE_KINDS, ResourceDisabled, ResourceInvalid, ResourceUnbound, RollbackTargetInvalid, SessionDeleted, SpawnCardinality, SwallowedYield, TRAINING_PROVIDER_CAPABILITY, TerminalIntegrationFailure, ToolUnavailable, UI_BUNDLE_BOUNDS, UnknownTool, WEB_FETCH_ARGUMENT_SCHEMA, WEB_SEARCH_ARGUMENT_SCHEMA, action, actionPattern, agent, agentResourceBinding, agentSetupMetadata, agentSetupRequirements, analyticsEvent, approximateTokens, authProvider, authProviderName, bindingName, bucketFor, canonicalJson, capabilityContractRef, casTool, channel, channelIngressRequest, channelIngressSource, channelSourceEvidence, channelSubscriptionRequest, channelTarget, checkpointArtifactRef, checkpointDeploymentRequest, checkpointImportMetadata, checkpointImportRequest, codeScorerIR, credentialEvidence, credentialInteractionAction, credentialInteractionEvent, credentialInteractionResult, credentialName, credentialProvider, credentialProviderConfigSchema, credentialProviderName, credentialProviderSetupMetadata, credentialRotationDefaults, credentialSetupState, customerTenantName, cutBatches, cutPartitions, datasetName, evaluateCodeScorer, evaluatePolicyDefinition, gateway, gatewayModelOffer, gatewayPackageMetadata, hash, hashValue, integrationEgressPolicy, labelSelector, matchesAction, matchesLabelSelector, matchesResource, memoryStoreBinding, modelAdvertisedPricing, modelControls, modelGatewayBinding, modelGatewayEndpoint, modelLimit, modelPrompt, modelProtocolRequest, modelProtocolResult, murmur3_32, normalizeModelGatewayConfig, normalizeSandboxNetworkPolicy, opTool, opTools, parseResourceName, policy, policyName, renderTrainingCompletion, resolveBindingOwner, resolveGatewayEgress, resolveResourceDependencyRef, resourceContractRef, resourceCredentialBinding, resourceDependencyRef, resourceLabelMap, resourceName, resourceNeed, resourcePattern, resourceSelector, sandboxControls, sandboxLimit, scopedBindingKey, scopedCredentialRef, scopedResourceRef, scorerName, selectableResourceLabels, setupAwait, setupCredentialReceipt, setupScreen, setupScreenView, setupSubmission, sha256Hex, stageOutput, startTrainingRequest, subtask, tableDescribe, tableQuery, trainingProvider, trainingProviderMetadata, trainingRecipe, uiBundle, uiBundleManifest, uiLimit, uiName, validateBatchSpec, validateFoldFn, validateJsonSchema, validateJsonSchemaDefinition, validatePartitionFn, validatePartitionSpec, validateStageOutputSpec, validateTool, validateView, webFetch, webSearch };
|
|
3874
|
+
export type { Action, ActionPattern, Actor, AdmissionLimitConstraint, AdmissionLimitInput, AdmissionLimitScope, AdmissionLimitWindow, Agent, AgentCredentialSetupRequirement, AgentDef, AgentDeployPolicy, AgentSetupMetadata, AgentSetupRequirement, AgentSetupWorkflow, AnalyticsClient, AnalyticsDimensionValue, AnalyticsEventDefinition, AnalyticsIntent, AnalyticsValues, AuthProvider, AuthProviderCRN, AuthProviderContext, AuthProviderRequest, AuthProviderResult, AwaitOpts, AwaitPresentation, BatchSpec, BindingCRN, BindingOwnerContext, BindingOwnerScope, BranchRef, CRN, CRNKind, CanonicalEvent, CanonicalEventDraft, CapabilityContractRef, CapabilityGrant, CapabilityRef, CaptureCaseRequest, CaseRow, CatalogTool, Channel, ChannelAlarm, ChannelAlarmResult, ChannelContext, ChannelIngressEvent, ChannelIngressSource, ChannelMessage, ChannelProtocol, ChannelReceiveResult, ChannelRequest, ChannelResponse, ChannelSourceEvidence, ChannelSubscriptionRequest, ChannelTarget, CheckpointDeploymentRequest, CheckpointImportMetadata, CheckpointImportRequest, CodeScoreResult, CodeScorerIR, CodeScorerRule, CommitOpts, CompareSuitesRequest, Compensation, ConnectionCancelRequest, ConnectionIdentity, ConnectionOperation, ConnectionRecoveryRequest, ConnectionRecoveryResult, ConnectionRequest, ConnectionUsageReport, ConstalApiApplyRequest, ConstalApiChangePlan, ConstalApiChangePlanRef, ConstalApiChangePlanRequest, ConstalApiChangeReceipt, ConstalApiOperationReceipt, ControlEvent, Cost, CreateSandboxImageOptions, CreateSandboxOptions, CredentialCRN, CredentialDestroyResult, CredentialEvidence, CredentialInteractionAction, CredentialInteractionAdvanceRequest, CredentialInteractionEvent, CredentialInteractionPrimaryAction, CredentialInteractionProof, CredentialInteractionResult, CredentialInteractionStartRequest, CredentialMaterialRequest, CredentialMintRequest, CredentialMintResult, CredentialProviderCRN, CredentialProviderContext, CredentialProviderCredentialSlotSetup, CredentialProviderDefinition, CredentialProviderPackage, CredentialProviderPackageMetadata, CredentialProviderSecretInput, CredentialProviderSetupMetadata, CredentialSetupState, CredentialVerifyResult, Ctx, CustomerTenantCRN, DataManifest, DatasetCRN, DatasetDraft, DatasetRef, DelegatedGrant, DelegationCeiling, DeliveryMode, DeliveryReceipt, DispatchResult, EffectClass, EvalComparison, EvalDivergence, EvalMode, EvalSubject, EvalSubjectSource, EventBase, Fact, FactRef, FileEntry, FixedMemoryStoreRef, FixedModelGatewayRef, FoldFn, GateEvidence, GateResult, GateVerdict, GatewayCancelRequest, GatewayConfigEgressBinding, GatewayContext, GatewayCredentialSlotSetup, GatewayDefinition, GatewayDiscoverySetup, GatewayModelOffer, GatewayOperation, GatewayPackage, GatewayPackageMetadata, GatewayRecoveryRequest, GatewayRecoveryResult, GatewayRequest, GovernanceContractRef, Handle, HandleOutcome, Hash, HistoryView, IgnoredChannelEvent, IngressRequest, IngressTarget, IntegrationArtifactEgressRequest, IntegrationArtifactEgressResponse, IntegrationContext, IntegrationEgressPolicy, IntegrationEgressRequest, IntegrationEgressResponse, IntegrationEgressRule, IntegrationSecret, IntegrationState, InvokableKind, InvokeOpts, JsonScalar, JsonValue, LabelRequest, LabelSelector, LabelSelectorOperator, LabelSelectorRequirement, LedgerAddress, LedgerEvent, LocalResourceRef, ManifestIndexPage, MapFact, MapOpts, MemoryDeleteArgs, MemoryGetArgs, MemoryRecord, MemoryRememberArgs, MemorySearchArgs, MemorySearchHit, MemoryStoreBinding, Mode, ModelAdvertisedPricing, ModelCredentialHeader, ModelGatewayBinding, ModelGatewayConfig, ModelGatewayProtocol, ModelGovernanceControls, ModelGovernanceMeter, ModelInvocationArgs, ModelInvocationResult, ModelTechnicalCapabilities, ModelTool, NormalizedModelGatewayConfig, Out, Over, PartitionFn, PartitionSpec, Partitioning, PolicyCRN, PolicyConstraint, PolicyContextValue, PolicyDefinition, PolicyInput, PolicyInvocationOrigin, PolicyOutcome, Principal, PrincipalKind, Provenance, RawModelProtocol, Recovery, ReduceFact, ReduceOpts, Ref, RequestLabelRequest, ResourceContractRef, ResourceControlsConstraint, ResourceCredentialBinding, ResourceDependencyRef, ResourceKind, ResourceName, ResourceNameParts, ResourceNeed, ResourcePattern, ResourceSelector, RollbackReport, RunIdentityView, RunInfo, RunStatusDetail, RunSuiteRequest, Sandbox, SandboxCommandResult, SandboxExecInput, SandboxFileResult, SandboxGovernanceControls, SandboxGovernanceMeter, SandboxImage, SandboxMutationResult, SandboxNetworkMode, SandboxNetworkPolicy, SandboxPool, SandboxReadFileOptions, SandboxReadFileResult, SandboxWriteFileResult, ScopedBindingKey, ScopedCredentialRef, ScopedMemoryStoreRef, ScopedModelGatewayRef, ScopedResourceRef, ScoreRequest, ScorerApplies, ScorerCRN, ScorerDef, ScorerEvaluation, ScorerKind, ScorerRef, ScorerVerdictIntent, SetEvalBaselineRequest, SetupAction, SetupCredentialCandidate, SetupCredentialInteractionPanel, SetupCredentialReceipt, SetupFormPanel, SetupPanel, SetupProgressPanel, SetupReviewPanel, SetupScreen, SetupStepStatus, SetupStepSummary, SetupSubmission, SetupTerminalPanel, SetupWorkflowStatus, SortField, SpawnAttenuation, SpawnBudget, SpawnOpts, SqlFold, StageInfo, StageOutputSpec, StartTrainingRequest, SteerEvent, SuiteFact, TableAggregate, TableDescribeArgs, TableFilter, TableFilterOperation, TableOrder, TableQueryArgs, TableQueryPlan, TableQueryResult, TableScalar, TableSnapshotDescription, Task, Tier, Tool, ToolCallRecord, TrainingJobFact, TrainingJobReference, TrainingJobState, TrainingJobStatus, TrainingMethod, TrainingModelOffer, TrainingProviderDefinition, TrainingProviderMetadata, TrainingProviderPin, TrainingRecipe, TrainingResumePoint, TrainingUsageUnits, TurnDraft, TurnGate, TurnRecord, TurnSpec, UiAccess, UiBundle, UiBundleManifest, UiCRN, UiCapability, UiExecution, UiGovernanceMeter, UiHandler, UiResource, UiRuntimeContext, UiSource, UiSqlResult, UiState, UpstreamPayer, Verdict, VerdictSamplingMode, ViewDef, WaitResolvedEvent };
|
package/publish/index.js
CHANGED
|
@@ -931,7 +931,11 @@ function validateFoldFn(fn) {
|
|
|
931
931
|
return fn;
|
|
932
932
|
}
|
|
933
933
|
function agent(input) {
|
|
934
|
-
const def = {
|
|
934
|
+
const def = {
|
|
935
|
+
...input,
|
|
936
|
+
version: input.version === void 0 ? "current" : input.version,
|
|
937
|
+
model: input.model === void 0 ? "model" : input.model
|
|
938
|
+
};
|
|
935
939
|
validateExecutable(def, "agent");
|
|
936
940
|
requiredString(def.model, "agent.model");
|
|
937
941
|
const mode = def.mode ?? "script";
|
|
@@ -1114,9 +1118,67 @@ function uiBundle(value, execution) {
|
|
|
1114
1118
|
return { manifest, modules: normalizedModules, assets: normalizedAssets };
|
|
1115
1119
|
}
|
|
1116
1120
|
|
|
1121
|
+
// src/ingress.ts
|
|
1122
|
+
var encoder3 = new TextEncoder();
|
|
1123
|
+
function object2(value) {
|
|
1124
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
1125
|
+
}
|
|
1126
|
+
function channelSourceEvidence(value) {
|
|
1127
|
+
const input = object2(value), channel2 = object2(input?.channel), authProvider2 = object2(input?.authProvider);
|
|
1128
|
+
if (!input || !channel2 || !authProvider2 || typeof authProvider2.crn !== "string" || typeof authProvider2.hash !== "string" || !/^[a-f0-9]{64}$/u.test(authProvider2.hash) || typeof channel2.crn !== "string" || typeof channel2.hash !== "string" || !/^[a-f0-9]{64}$/u.test(channel2.hash) || typeof input.id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u.test(input.id) || typeof input.requestHash !== "string" || !/^[a-f0-9]{64}$/u.test(input.requestHash)) throw new TypeError("Channel source evidence is invalid");
|
|
1129
|
+
const source = channelIngressSource(input.source), name = parseResourceName(channel2.crn), authentication = parseResourceName(authProvider2.crn);
|
|
1130
|
+
if (name.kind !== "channel" || name.tenant !== "platform" || name.namespace !== "ingress" || name.path !== source.provider || authentication.kind !== "auth-provider" || authentication.environment !== name.environment || authentication.tenant !== name.tenant || authentication.namespace !== name.namespace) {
|
|
1131
|
+
throw new TypeError("Channel source evidence is outside its source");
|
|
1132
|
+
}
|
|
1133
|
+
return { channel: { crn: channel2.crn, hash: channel2.hash }, authProvider: { crn: authProvider2.crn, hash: authProvider2.hash }, source, id: input.id, requestHash: input.requestHash };
|
|
1134
|
+
}
|
|
1135
|
+
function credentialEvidence(value) {
|
|
1136
|
+
const input = object2(value), provider = object2(input?.provider), claims = object2(input?.claims);
|
|
1137
|
+
if (!input || typeof input.credential !== "string" || !provider || typeof provider.crn !== "string" || typeof provider.hash !== "string" || !/^[a-f0-9]{64}$/u.test(provider.hash) || !Number.isSafeInteger(input.version) || Number(input.version) < 1 || input.expiresAt !== null && (!Number.isSafeInteger(input.expiresAt) || Number(input.expiresAt) < 1) || !claims || Object.keys(claims).length > 32 || encoder3.encode(JSON.stringify(claims)).byteLength > 65536 || Object.entries(claims).some(([key, value2]) => !/^[A-Za-z0-9._-]{1,128}$/u.test(key) || !(typeof value2 === "string" && value2.length <= 2048 || typeof value2 === "boolean" || typeof value2 === "number" && Number.isFinite(value2) || Array.isArray(value2) && value2.length <= 500 && value2.every((item) => typeof item === "string" && item.length <= 256)))) {
|
|
1138
|
+
throw new TypeError("Credential evidence is invalid");
|
|
1139
|
+
}
|
|
1140
|
+
if (parseResourceName(input.credential).kind !== "credential" || parseResourceName(provider.crn).kind !== "credential-provider") {
|
|
1141
|
+
throw new TypeError("Credential evidence identity is invalid");
|
|
1142
|
+
}
|
|
1143
|
+
return {
|
|
1144
|
+
credential: input.credential,
|
|
1145
|
+
provider: { crn: provider.crn, hash: provider.hash },
|
|
1146
|
+
version: Number(input.version),
|
|
1147
|
+
expiresAt: input.expiresAt,
|
|
1148
|
+
claims
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
function channelIngressSource(value) {
|
|
1152
|
+
const source = object2(value);
|
|
1153
|
+
if (!source || typeof source.provider !== "string" || !/^[a-z0-9][a-z0-9._-]{0,63}$/u.test(source.provider) || typeof source.key !== "string" || !/^[A-Za-z0-9._:-]{1,256}$/u.test(source.key)) throw new TypeError("Channel ingress source is invalid");
|
|
1154
|
+
return { provider: source.provider, key: source.key };
|
|
1155
|
+
}
|
|
1156
|
+
function channelSubscriptionRequest(value) {
|
|
1157
|
+
const input = object2(value), configuration = object2(input?.configuration);
|
|
1158
|
+
if (!input || !configuration || typeof input.channel !== "string" || typeof input.principal !== "string") throw new TypeError("Channel subscription is invalid");
|
|
1159
|
+
const channel2 = parseResourceName(input.channel), principal = parseResourceName(input.principal);
|
|
1160
|
+
if (channel2.kind !== "channel" || principal.kind !== "principal" || channel2.environment !== principal.environment || channel2.tenant !== principal.tenant) {
|
|
1161
|
+
throw new TypeError("Channel subscription crosses the authenticated tenant");
|
|
1162
|
+
}
|
|
1163
|
+
const credentials = input.credentials ?? [];
|
|
1164
|
+
if (!Array.isArray(credentials) || credentials.length > 32) throw new TypeError("Channel subscription Credentials are invalid");
|
|
1165
|
+
const proofs = credentials.map(credentialEvidence);
|
|
1166
|
+
for (const proof of proofs) {
|
|
1167
|
+
const owner = parseResourceName(proof.credential), provider = parseResourceName(proof.provider.crn);
|
|
1168
|
+
if (owner.tenant !== channel2.tenant || owner.environment !== channel2.environment || provider.environment !== channel2.environment) {
|
|
1169
|
+
throw new TypeError("Channel subscription Credential crosses the authenticated tenant");
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return { source: channelIngressSource(input.source), channel: input.channel, principal: input.principal, configuration, credentials: proofs };
|
|
1173
|
+
}
|
|
1174
|
+
function channelIngressRequest(value) {
|
|
1175
|
+
const input = object2(value), headers = object2(input?.headers);
|
|
1176
|
+
if (!input || !["GET", "POST", "PUT", "PATCH", "DELETE"].includes(String(input.method)) || typeof input.url !== "string" || !input.url || input.url.length > 2048 || !headers || Object.keys(headers).length > 128 || Object.entries(headers).some(([key, value2]) => !/^[a-z0-9-]{1,128}$/u.test(key) || typeof value2 !== "string" || value2.length > 8192) || input.bodyBase64 !== null && (typeof input.bodyBase64 !== "string" || input.bodyBase64.length > 5592408) || encoder3.encode(JSON.stringify(input)).byteLength > 6 * 1024 * 1024) throw new TypeError("Channel ingress request is invalid");
|
|
1177
|
+
return { method: input.method, url: input.url, headers, bodyBase64: input.bodyBase64 };
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1117
1180
|
// src/setup-workflow.ts
|
|
1118
1181
|
var ID = /^[a-z0-9][a-z0-9-]{0,62}$/u;
|
|
1119
|
-
var CRN = /^crn:constal:[a-z0-9-]+:[a-z0-9-]+:[a-z0-9-]+:credential-provider\/[A-Za-z0-9._~/%-]{1,512}$/u;
|
|
1120
1182
|
var MAX_SCREEN_BYTES = 262144;
|
|
1121
1183
|
function record3(value) {
|
|
1122
1184
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
@@ -1161,13 +1223,38 @@ function panel(value) {
|
|
|
1161
1223
|
if (source.kind === "credential-interaction") {
|
|
1162
1224
|
const provider = text(source.provider, 1024);
|
|
1163
1225
|
const credentialId = text(source.credentialId, 63);
|
|
1164
|
-
if (!provider || !
|
|
1226
|
+
if (!provider || !credentialId || !ID.test(credentialId) || !["connect", "reauthorize", "manage"].includes(String(source.operation)) || source.receipt !== void 0 && !["reference", "evidence"].includes(String(source.receipt)) || source.receipt !== void 0 && base.actions.filter((action3) => action3.intent === "primary").length !== 1 || (source.selection !== void 0 || source.configuration !== void 0) && source.receipt === void 0 || source.configuration !== void 0 && !record3(source.configuration) || !exact(source, ["kind", "id", "title", "description", "actions", "provider", "credentialId", "operation", "receipt", "selection", "configuration"])) return null;
|
|
1227
|
+
try {
|
|
1228
|
+
if (parseResourceName(provider).kind !== "credential-provider") return null;
|
|
1229
|
+
} catch {
|
|
1230
|
+
return null;
|
|
1231
|
+
}
|
|
1232
|
+
let selection;
|
|
1233
|
+
if (source.selection !== void 0) {
|
|
1234
|
+
const input = record3(source.selection);
|
|
1235
|
+
if (!input || !exact(input, ["selector", "binding"]) || !record3(input.selector)) return null;
|
|
1236
|
+
try {
|
|
1237
|
+
const requirement = agentSetupRequirements([{
|
|
1238
|
+
id: base.id,
|
|
1239
|
+
title: base.title,
|
|
1240
|
+
resourceKind: "credential",
|
|
1241
|
+
selector: input.selector,
|
|
1242
|
+
binding: input.binding
|
|
1243
|
+
}])[0];
|
|
1244
|
+
selection = { selector: requirement.selector, binding: requirement.binding };
|
|
1245
|
+
} catch {
|
|
1246
|
+
return null;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1165
1249
|
return {
|
|
1166
1250
|
...base,
|
|
1167
1251
|
kind: "credential-interaction",
|
|
1168
1252
|
provider,
|
|
1169
1253
|
credentialId,
|
|
1170
|
-
operation: source.operation
|
|
1254
|
+
operation: source.operation,
|
|
1255
|
+
...source.receipt === void 0 ? {} : { receipt: source.receipt },
|
|
1256
|
+
...selection ? { selection } : {},
|
|
1257
|
+
...source.configuration === void 0 ? {} : { configuration: source.configuration }
|
|
1171
1258
|
};
|
|
1172
1259
|
}
|
|
1173
1260
|
if (source.kind === "review") {
|
|
@@ -1260,6 +1347,9 @@ function setupSubmission(value, screen) {
|
|
|
1260
1347
|
const error = validateJsonSchema(values ?? {}, screen.current.schema, "$setup.submission.values");
|
|
1261
1348
|
if (error) throw new TypeError(error);
|
|
1262
1349
|
}
|
|
1350
|
+
if (screen.current.kind === "credential-interaction" && screen.current.receipt !== void 0 && source.action === screen.current.actions.find(({ intent }) => intent === "primary")?.id) {
|
|
1351
|
+
setupCredentialReceipt(values, screen.current);
|
|
1352
|
+
}
|
|
1263
1353
|
return {
|
|
1264
1354
|
object: "constal.setup.submission",
|
|
1265
1355
|
version: 1,
|
|
@@ -1270,8 +1360,78 @@ function setupSubmission(value, screen) {
|
|
|
1270
1360
|
...values ? { values } : {}
|
|
1271
1361
|
};
|
|
1272
1362
|
}
|
|
1363
|
+
function setupCredentialReceipt(value, panel2) {
|
|
1364
|
+
const source = record3(value), credential = record3(source?.credential), binding = record3(source?.binding);
|
|
1365
|
+
const hash3 = (value2) => typeof value2 === "string" && /^[a-f0-9]{64}$/u.test(value2);
|
|
1366
|
+
if (!panel2.receipt || !source || source.object !== "constal.setup.credential" || source.version !== 1 || !exact(source, ["object", "version", "credential", "evidence", "binding"]) || !credential || !exact(credential, ["crn", "hash"]) || typeof credential.crn !== "string" || !hash3(credential.hash)) {
|
|
1367
|
+
throw new TypeError("Setup Credential receipt is invalid");
|
|
1368
|
+
}
|
|
1369
|
+
const target = parseResourceName(credential.crn), provider = parseResourceName(panel2.provider);
|
|
1370
|
+
if (target.kind !== "credential" || target.environment !== provider.environment || provider.tenant !== "platform" && provider.tenant !== target.tenant) throw new TypeError("Setup Credential receipt identity is invalid");
|
|
1371
|
+
const evidence = source.evidence === null ? null : credentialEvidence(source.evidence);
|
|
1372
|
+
if (panel2.receipt === "evidence" && !evidence || panel2.receipt === "reference" && evidence || evidence && (evidence.credential !== credential.crn || evidence.provider.crn !== panel2.provider)) {
|
|
1373
|
+
throw new TypeError("Setup Credential evidence does not match its step");
|
|
1374
|
+
}
|
|
1375
|
+
if (panel2.selection) {
|
|
1376
|
+
if (!binding || !exact(binding, ["crn", "headSeq", "revisionHash"]) || typeof binding.crn !== "string" || !Number.isSafeInteger(binding.headSeq) || Number(binding.headSeq) < 1 || !hash3(binding.revisionHash)) {
|
|
1377
|
+
throw new TypeError("Setup Credential binding receipt is invalid");
|
|
1378
|
+
}
|
|
1379
|
+
const owner = parseResourceName(binding.crn);
|
|
1380
|
+
if (owner.kind !== "binding" || owner.tenant !== target.tenant || owner.environment !== target.environment) {
|
|
1381
|
+
throw new TypeError("Setup Credential binding receipt is outside its tenant");
|
|
1382
|
+
}
|
|
1383
|
+
} else if (source.binding !== null) throw new TypeError("Setup Credential step did not declare a binding");
|
|
1384
|
+
return {
|
|
1385
|
+
object: "constal.setup.credential",
|
|
1386
|
+
version: 1,
|
|
1387
|
+
credential: { crn: credential.crn, hash: credential.hash },
|
|
1388
|
+
evidence,
|
|
1389
|
+
binding: binding ? { crn: binding.crn, headSeq: Number(binding.headSeq), revisionHash: binding.revisionHash } : null
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1273
1392
|
function setupAwait(screen) {
|
|
1274
1393
|
if (screen.status !== "active" || !screen.waitLabel) throw new TypeError("Only an active Setup screen can open a wait");
|
|
1394
|
+
const current = screen.current;
|
|
1395
|
+
const hash3 = { type: "string", pattern: "^[a-f0-9]{64}$" };
|
|
1396
|
+
const reference = {
|
|
1397
|
+
type: "object",
|
|
1398
|
+
additionalProperties: false,
|
|
1399
|
+
required: ["crn", "hash"],
|
|
1400
|
+
properties: { crn: { type: "string", maxLength: 1024 }, hash: hash3 }
|
|
1401
|
+
};
|
|
1402
|
+
const receipt = current.kind === "credential-interaction" && current.receipt !== void 0 ? {
|
|
1403
|
+
type: "object",
|
|
1404
|
+
additionalProperties: false,
|
|
1405
|
+
required: ["object", "version", "credential", "evidence", "binding"],
|
|
1406
|
+
properties: {
|
|
1407
|
+
object: { const: "constal.setup.credential" },
|
|
1408
|
+
version: { const: 1 },
|
|
1409
|
+
credential: reference,
|
|
1410
|
+
evidence: current.receipt === "reference" ? { type: "null" } : {
|
|
1411
|
+
type: "object",
|
|
1412
|
+
additionalProperties: false,
|
|
1413
|
+
required: ["credential", "provider", "version", "expiresAt", "claims"],
|
|
1414
|
+
properties: {
|
|
1415
|
+
credential: { type: "string", maxLength: 1024 },
|
|
1416
|
+
provider: {
|
|
1417
|
+
...reference,
|
|
1418
|
+
properties: { crn: { const: current.provider }, hash: hash3 }
|
|
1419
|
+
},
|
|
1420
|
+
version: { type: "integer", minimum: 1 },
|
|
1421
|
+
expiresAt: { type: ["integer", "null"], minimum: 1 },
|
|
1422
|
+
claims: { type: "object", maxProperties: 32 }
|
|
1423
|
+
}
|
|
1424
|
+
},
|
|
1425
|
+
binding: current.selection ? {
|
|
1426
|
+
type: "object",
|
|
1427
|
+
additionalProperties: false,
|
|
1428
|
+
required: ["crn", "headSeq", "revisionHash"],
|
|
1429
|
+
properties: { crn: { type: "string", maxLength: 1024 }, headSeq: { type: "integer", minimum: 1 }, revisionHash: hash3 }
|
|
1430
|
+
} : { type: "null" }
|
|
1431
|
+
}
|
|
1432
|
+
} : null;
|
|
1433
|
+
const primary = current.actions.find((action3) => action3.intent === "primary");
|
|
1434
|
+
const secondary = current.actions.filter((action3) => action3.id !== primary?.id).map((action3) => action3.id);
|
|
1275
1435
|
return { maxBytes: 262144, schema: {
|
|
1276
1436
|
type: "object",
|
|
1277
1437
|
additionalProperties: false,
|
|
@@ -1284,7 +1444,11 @@ function setupAwait(screen) {
|
|
|
1284
1444
|
step: { const: screen.current.id },
|
|
1285
1445
|
action: { enum: screen.current.actions.map(({ id: id2 }) => id2) },
|
|
1286
1446
|
values: { type: "object", additionalProperties: true }
|
|
1287
|
-
}
|
|
1447
|
+
},
|
|
1448
|
+
...receipt && primary ? { anyOf: [
|
|
1449
|
+
{ required: ["values"], properties: { action: { const: primary.id }, values: receipt } },
|
|
1450
|
+
...secondary.length ? [{ properties: { action: { enum: secondary } } }] : []
|
|
1451
|
+
] } : {}
|
|
1288
1452
|
} };
|
|
1289
1453
|
}
|
|
1290
1454
|
function setupScreenView(id2 = "setup-screen") {
|
|
@@ -1345,65 +1509,6 @@ function credentialSetupState(requirement, scope2, inventory, binding) {
|
|
|
1345
1509
|
};
|
|
1346
1510
|
}
|
|
1347
1511
|
|
|
1348
|
-
// src/ingress.ts
|
|
1349
|
-
var encoder3 = new TextEncoder();
|
|
1350
|
-
function object2(value) {
|
|
1351
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
1352
|
-
}
|
|
1353
|
-
function channelSourceEvidence(value) {
|
|
1354
|
-
const input = object2(value), channel2 = object2(input?.channel), authProvider2 = object2(input?.authProvider);
|
|
1355
|
-
if (!input || !channel2 || !authProvider2 || typeof authProvider2.crn !== "string" || typeof authProvider2.hash !== "string" || !/^[a-f0-9]{64}$/u.test(authProvider2.hash) || typeof channel2.crn !== "string" || typeof channel2.hash !== "string" || !/^[a-f0-9]{64}$/u.test(channel2.hash) || typeof input.id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u.test(input.id) || typeof input.requestHash !== "string" || !/^[a-f0-9]{64}$/u.test(input.requestHash)) throw new TypeError("Channel source evidence is invalid");
|
|
1356
|
-
const source = channelIngressSource(input.source), name = parseResourceName(channel2.crn), authentication = parseResourceName(authProvider2.crn);
|
|
1357
|
-
if (name.kind !== "channel" || name.tenant !== "platform" || name.namespace !== "ingress" || name.path !== source.provider || authentication.kind !== "auth-provider" || authentication.environment !== name.environment || authentication.tenant !== name.tenant || authentication.namespace !== name.namespace) {
|
|
1358
|
-
throw new TypeError("Channel source evidence is outside its source");
|
|
1359
|
-
}
|
|
1360
|
-
return { channel: { crn: channel2.crn, hash: channel2.hash }, authProvider: { crn: authProvider2.crn, hash: authProvider2.hash }, source, id: input.id, requestHash: input.requestHash };
|
|
1361
|
-
}
|
|
1362
|
-
function credentialEvidence(value) {
|
|
1363
|
-
const input = object2(value), provider = object2(input?.provider), claims = object2(input?.claims);
|
|
1364
|
-
if (!input || typeof input.credential !== "string" || !provider || typeof provider.crn !== "string" || typeof provider.hash !== "string" || !/^[a-f0-9]{64}$/u.test(provider.hash) || !Number.isSafeInteger(input.version) || Number(input.version) < 1 || input.expiresAt !== null && (!Number.isSafeInteger(input.expiresAt) || Number(input.expiresAt) < 1) || !claims || Object.keys(claims).length > 32 || encoder3.encode(JSON.stringify(claims)).byteLength > 65536 || Object.entries(claims).some(([key, value2]) => !/^[A-Za-z0-9._-]{1,128}$/u.test(key) || !(typeof value2 === "string" && value2.length <= 2048 || typeof value2 === "boolean" || typeof value2 === "number" && Number.isFinite(value2) || Array.isArray(value2) && value2.length <= 500 && value2.every((item) => typeof item === "string" && item.length <= 256)))) {
|
|
1365
|
-
throw new TypeError("Credential evidence is invalid");
|
|
1366
|
-
}
|
|
1367
|
-
if (parseResourceName(input.credential).kind !== "credential" || parseResourceName(provider.crn).kind !== "credential-provider") {
|
|
1368
|
-
throw new TypeError("Credential evidence identity is invalid");
|
|
1369
|
-
}
|
|
1370
|
-
return {
|
|
1371
|
-
credential: input.credential,
|
|
1372
|
-
provider: { crn: provider.crn, hash: provider.hash },
|
|
1373
|
-
version: Number(input.version),
|
|
1374
|
-
expiresAt: input.expiresAt,
|
|
1375
|
-
claims
|
|
1376
|
-
};
|
|
1377
|
-
}
|
|
1378
|
-
function channelIngressSource(value) {
|
|
1379
|
-
const source = object2(value);
|
|
1380
|
-
if (!source || typeof source.provider !== "string" || !/^[a-z0-9][a-z0-9._-]{0,63}$/u.test(source.provider) || typeof source.key !== "string" || !/^[A-Za-z0-9._:-]{1,256}$/u.test(source.key)) throw new TypeError("Channel ingress source is invalid");
|
|
1381
|
-
return { provider: source.provider, key: source.key };
|
|
1382
|
-
}
|
|
1383
|
-
function channelSubscriptionRequest(value) {
|
|
1384
|
-
const input = object2(value), configuration = object2(input?.configuration);
|
|
1385
|
-
if (!input || !configuration || typeof input.channel !== "string" || typeof input.principal !== "string") throw new TypeError("Channel subscription is invalid");
|
|
1386
|
-
const channel2 = parseResourceName(input.channel), principal = parseResourceName(input.principal);
|
|
1387
|
-
if (channel2.kind !== "channel" || principal.kind !== "principal" || channel2.environment !== principal.environment || channel2.tenant !== principal.tenant) {
|
|
1388
|
-
throw new TypeError("Channel subscription crosses the authenticated tenant");
|
|
1389
|
-
}
|
|
1390
|
-
const credentials = input.credentials ?? [];
|
|
1391
|
-
if (!Array.isArray(credentials) || credentials.length > 32) throw new TypeError("Channel subscription Credentials are invalid");
|
|
1392
|
-
const proofs = credentials.map(credentialEvidence);
|
|
1393
|
-
for (const proof of proofs) {
|
|
1394
|
-
const owner = parseResourceName(proof.credential), provider = parseResourceName(proof.provider.crn);
|
|
1395
|
-
if (owner.tenant !== channel2.tenant || owner.environment !== channel2.environment || provider.environment !== channel2.environment) {
|
|
1396
|
-
throw new TypeError("Channel subscription Credential crosses the authenticated tenant");
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
return { source: channelIngressSource(input.source), channel: input.channel, principal: input.principal, configuration, credentials: proofs };
|
|
1400
|
-
}
|
|
1401
|
-
function channelIngressRequest(value) {
|
|
1402
|
-
const input = object2(value), headers = object2(input?.headers);
|
|
1403
|
-
if (!input || !["GET", "POST", "PUT", "PATCH", "DELETE"].includes(String(input.method)) || typeof input.url !== "string" || !input.url || input.url.length > 2048 || !headers || Object.keys(headers).length > 128 || Object.entries(headers).some(([key, value2]) => !/^[a-z0-9-]{1,128}$/u.test(key) || typeof value2 !== "string" || value2.length > 8192) || input.bodyBase64 !== null && (typeof input.bodyBase64 !== "string" || input.bodyBase64.length > 5592408) || encoder3.encode(JSON.stringify(input)).byteLength > 6 * 1024 * 1024) throw new TypeError("Channel ingress request is invalid");
|
|
1404
|
-
return { method: input.method, url: input.url, headers, bodyBase64: input.bodyBase64 };
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
1512
|
// src/constal-api.ts
|
|
1408
1513
|
var CONSTAL_API_CAPABILITY = "constal.api";
|
|
1409
1514
|
var CONSTAL_API_VERSION = "1";
|
|
@@ -1722,11 +1827,11 @@ function sandboxControls(values) {
|
|
|
1722
1827
|
function sandboxLimit(input) {
|
|
1723
1828
|
return limit(SANDBOX_CONTRACT, ["commands", "compute_ms", "file_bytes", "requests"], input);
|
|
1724
1829
|
}
|
|
1725
|
-
function modelControls(values) {
|
|
1726
|
-
return controls(
|
|
1830
|
+
function modelControls(values, contract = MODEL_CONTRACT) {
|
|
1831
|
+
return controls(contract, values, modelSchema);
|
|
1727
1832
|
}
|
|
1728
|
-
function modelLimit(input) {
|
|
1729
|
-
return limit(
|
|
1833
|
+
function modelLimit(input, contract = MODEL_CONTRACT) {
|
|
1834
|
+
return limit(contract, ["cached_input_tokens", "input_tokens", "output_tokens", "requests"], input);
|
|
1730
1835
|
}
|
|
1731
1836
|
function uiLimit(input) {
|
|
1732
1837
|
return limit(UI_CONTRACT, ["requests"], input);
|
|
@@ -2378,6 +2483,190 @@ Response:
|
|
|
2378
2483
|
`, completion: expected === void 0 || expected === null ? null : text2(expected) };
|
|
2379
2484
|
}
|
|
2380
2485
|
|
|
2486
|
+
// src/model.ts
|
|
2487
|
+
var MODEL_COMPLETION_CAPABILITY = {
|
|
2488
|
+
id: "constal.model-completion",
|
|
2489
|
+
version: "1",
|
|
2490
|
+
hash: "0155be6df18b64e7f91ce9939b3c18527813f3dd06260fe65821ed071d94516a"
|
|
2491
|
+
};
|
|
2492
|
+
function modelGenerationOptions(source) {
|
|
2493
|
+
const { maxOutputTokens, temperature, effort } = source;
|
|
2494
|
+
if (maxOutputTokens !== void 0 && (!Number.isSafeInteger(maxOutputTokens) || maxOutputTokens < 1 || maxOutputTokens > 1048576)) {
|
|
2495
|
+
throw new TypeError("maxOutputTokens must be an integer from 1 to 1048576");
|
|
2496
|
+
}
|
|
2497
|
+
if (temperature !== void 0 && (typeof temperature !== "number" || !Number.isFinite(temperature) || temperature < 0 || temperature > 2)) {
|
|
2498
|
+
throw new TypeError("temperature must be a finite number from 0 to 2");
|
|
2499
|
+
}
|
|
2500
|
+
if (effort !== void 0 && (typeof effort !== "string" || !effort.trim())) {
|
|
2501
|
+
throw new TypeError("effort must be a nonempty model-supported string");
|
|
2502
|
+
}
|
|
2503
|
+
return {
|
|
2504
|
+
...maxOutputTokens === void 0 ? {} : { maxOutputTokens },
|
|
2505
|
+
...temperature === void 0 ? {} : { temperature },
|
|
2506
|
+
...effort === void 0 ? {} : { effort }
|
|
2507
|
+
};
|
|
2508
|
+
}
|
|
2509
|
+
var NAME4 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
2510
|
+
var HEADER = /^[a-z0-9][a-z0-9-]{0,63}$/u;
|
|
2511
|
+
var RESERVED_HEADERS = /* @__PURE__ */ new Set(["connection", "content-type", "host", "anthropic-version", "proxy-authorization", "transfer-encoding"]);
|
|
2512
|
+
function record7(value) {
|
|
2513
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
2514
|
+
}
|
|
2515
|
+
function credentialHeader(value, name) {
|
|
2516
|
+
if (value === null || value === void 0) return null;
|
|
2517
|
+
const source = record7(value);
|
|
2518
|
+
if (!source || typeof source.slot !== "string" || !NAME4.test(source.slot) || typeof source.header !== "string" || !HEADER.test(source.header.toLowerCase()) || RESERVED_HEADERS.has(source.header.toLowerCase()) || source.header.toLowerCase().startsWith("cf-") || source.scheme !== "bearer" && source.scheme !== "raw") throw new TypeError(`${name} is invalid`);
|
|
2519
|
+
return { slot: source.slot, header: source.header.toLowerCase(), scheme: source.scheme };
|
|
2520
|
+
}
|
|
2521
|
+
function normalizeModelGatewayConfig(value) {
|
|
2522
|
+
const source = record7(value);
|
|
2523
|
+
if (!source || typeof source.baseUrl !== "string" || source.baseUrl.length > 2048 || source.protocol !== "anthropic" && source.protocol !== "openai" || typeof source.model !== "string" || source.model.length === 0 || source.model.length > 256) {
|
|
2524
|
+
throw new TypeError("model gateway config is invalid");
|
|
2525
|
+
}
|
|
2526
|
+
const maxOutputTokens = source.maxOutputTokens === void 0 ? 256 : Number(source.maxOutputTokens);
|
|
2527
|
+
const temperature = source.temperature === void 0 ? null : Number(source.temperature);
|
|
2528
|
+
if (!Number.isSafeInteger(maxOutputTokens) || maxOutputTokens < 1 || maxOutputTokens > 8192 || temperature !== null && (!Number.isFinite(temperature) || temperature < 0 || temperature > 2)) {
|
|
2529
|
+
throw new TypeError("model gateway generation limits are invalid");
|
|
2530
|
+
}
|
|
2531
|
+
const normalized = {
|
|
2532
|
+
baseUrl: source.baseUrl,
|
|
2533
|
+
protocol: source.protocol,
|
|
2534
|
+
model: source.model,
|
|
2535
|
+
maxOutputTokens,
|
|
2536
|
+
temperature,
|
|
2537
|
+
gatewayAuth: credentialHeader(source.gatewayAuth, "gatewayAuth"),
|
|
2538
|
+
providerAuth: credentialHeader(source.providerAuth, "providerAuth")
|
|
2539
|
+
};
|
|
2540
|
+
if (normalized.gatewayAuth && normalized.providerAuth && normalized.gatewayAuth.header === normalized.providerAuth.header) {
|
|
2541
|
+
throw new TypeError("gateway and provider credentials cannot share one header");
|
|
2542
|
+
}
|
|
2543
|
+
if (normalized.gatewayAuth && normalized.providerAuth && normalized.gatewayAuth.slot === normalized.providerAuth.slot) {
|
|
2544
|
+
throw new TypeError("gateway and provider credentials cannot share one slot");
|
|
2545
|
+
}
|
|
2546
|
+
modelGatewayEndpoint(normalized);
|
|
2547
|
+
return normalized;
|
|
2548
|
+
}
|
|
2549
|
+
function modelGatewayEndpoint(config) {
|
|
2550
|
+
let endpoint;
|
|
2551
|
+
try {
|
|
2552
|
+
endpoint = new URL(config.baseUrl);
|
|
2553
|
+
} catch {
|
|
2554
|
+
throw new TypeError("model gateway baseUrl is invalid");
|
|
2555
|
+
}
|
|
2556
|
+
if (endpoint.protocol !== "https:" || endpoint.username || endpoint.password || endpoint.search || endpoint.hash) {
|
|
2557
|
+
throw new TypeError("model gateway baseUrl must be a credential-free HTTPS URL");
|
|
2558
|
+
}
|
|
2559
|
+
const hostname = endpoint.hostname.toLowerCase();
|
|
2560
|
+
if (hostname === "localhost" || hostname.endsWith(".localhost") || hostname.endsWith(".local") || hostname.endsWith(".internal")) {
|
|
2561
|
+
throw new TypeError("model gateway baseUrl must use a public hostname");
|
|
2562
|
+
}
|
|
2563
|
+
const suffix = config.protocol === "anthropic" ? "v1/messages" : config.protocol === "openai" ? "v1/chat/completions" : null;
|
|
2564
|
+
if (!suffix) throw new TypeError("model gateway protocol is invalid");
|
|
2565
|
+
endpoint.pathname = `${endpoint.pathname.replace(/\/+$/u, "")}/${suffix}`.replace(/^\/+/u, "/");
|
|
2566
|
+
return endpoint;
|
|
2567
|
+
}
|
|
2568
|
+
function modelPrompt(args) {
|
|
2569
|
+
return JSON.stringify({ objective: args.objective ?? null, context: args.context ?? null, feedback: args.feedback ?? [] });
|
|
2570
|
+
}
|
|
2571
|
+
function modelProtocolRequest(protocol, model, maxOutputTokens, temperature, args) {
|
|
2572
|
+
const { effort } = modelGenerationOptions(args);
|
|
2573
|
+
if (args.toolChoice !== void 0 && args.toolChoice !== "auto" && args.toolChoice !== "required") {
|
|
2574
|
+
throw new TypeError("model Tool choice is invalid");
|
|
2575
|
+
}
|
|
2576
|
+
if (args.toolChoice === "required" && !args.tools?.length) {
|
|
2577
|
+
throw new TypeError("required model Tool choice needs at least one offered Tool");
|
|
2578
|
+
}
|
|
2579
|
+
const prompt = modelPrompt(args);
|
|
2580
|
+
if (protocol === "anthropic") return {
|
|
2581
|
+
model,
|
|
2582
|
+
system: args.system ?? "",
|
|
2583
|
+
messages: [{ role: "user", content: prompt }],
|
|
2584
|
+
max_tokens: maxOutputTokens,
|
|
2585
|
+
...effort === void 0 ? {} : { output_config: { effort } },
|
|
2586
|
+
...temperature === null ? {} : { temperature },
|
|
2587
|
+
...args.tools?.length ? { tools: args.tools.map((tool) => ({ name: tool.name, description: tool.description, input_schema: tool.schema })) } : {},
|
|
2588
|
+
...args.toolChoice === void 0 ? {} : { tool_choice: { type: args.toolChoice === "required" ? "any" : "auto" } }
|
|
2589
|
+
};
|
|
2590
|
+
if (protocol === "openai") return {
|
|
2591
|
+
model,
|
|
2592
|
+
messages: [
|
|
2593
|
+
...args.system ? [{ role: "developer", content: args.system }] : [],
|
|
2594
|
+
{ role: "user", content: prompt }
|
|
2595
|
+
],
|
|
2596
|
+
max_completion_tokens: maxOutputTokens,
|
|
2597
|
+
...effort === void 0 ? {} : { reasoning_effort: effort },
|
|
2598
|
+
...temperature === null ? {} : { temperature },
|
|
2599
|
+
...args.tools?.length ? { tools: args.tools.map((tool) => ({
|
|
2600
|
+
type: "function",
|
|
2601
|
+
function: { name: tool.name, description: tool.description, parameters: tool.schema }
|
|
2602
|
+
})) } : {},
|
|
2603
|
+
...args.toolChoice === void 0 ? {} : { tool_choice: args.toolChoice }
|
|
2604
|
+
};
|
|
2605
|
+
throw new TypeError("model gateway protocol is invalid");
|
|
2606
|
+
}
|
|
2607
|
+
function integer2(value) {
|
|
2608
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
2609
|
+
}
|
|
2610
|
+
function costMetadata(usage) {
|
|
2611
|
+
const cost = usage.cost;
|
|
2612
|
+
const costUsd = cost === null ? null : typeof cost === "number" && Number.isFinite(cost) && cost >= 0 ? cost : void 0;
|
|
2613
|
+
return {
|
|
2614
|
+
...costUsd !== void 0 ? { costUsd } : {},
|
|
2615
|
+
...typeof usage.cost_source === "string" ? { costSource: usage.cost_source } : {},
|
|
2616
|
+
...typeof usage.cost_estimated === "boolean" ? { costEstimated: usage.cost_estimated } : {}
|
|
2617
|
+
};
|
|
2618
|
+
}
|
|
2619
|
+
function modelProtocolResult(protocol, raw, provider, model) {
|
|
2620
|
+
const source = record7(raw) ?? {};
|
|
2621
|
+
const toolCalls = [];
|
|
2622
|
+
let content2 = "";
|
|
2623
|
+
let usage;
|
|
2624
|
+
if (protocol === "anthropic") {
|
|
2625
|
+
const blocks = Array.isArray(source.content) ? source.content : [];
|
|
2626
|
+
content2 = blocks.map((candidate) => {
|
|
2627
|
+
const block = record7(candidate);
|
|
2628
|
+
if (block?.type === "text" && typeof block.text === "string") return block.text;
|
|
2629
|
+
if (block?.type === "tool_use" && typeof block.id === "string" && typeof block.name === "string") {
|
|
2630
|
+
toolCalls.push({ id: block.id, name: block.name, args: block.input ?? {} });
|
|
2631
|
+
}
|
|
2632
|
+
return "";
|
|
2633
|
+
}).join("");
|
|
2634
|
+
const values = record7(source.usage) ?? {};
|
|
2635
|
+
const cached = integer2(values.cache_read_input_tokens);
|
|
2636
|
+
usage = {
|
|
2637
|
+
input: integer2(values.input_tokens) + integer2(values.cache_creation_input_tokens) + cached,
|
|
2638
|
+
output: integer2(values.output_tokens),
|
|
2639
|
+
cached,
|
|
2640
|
+
...costMetadata(values)
|
|
2641
|
+
};
|
|
2642
|
+
} else if (protocol === "openai") {
|
|
2643
|
+
const choice = record7(Array.isArray(source.choices) ? source.choices[0] : null) ?? {};
|
|
2644
|
+
const message = record7(choice.message) ?? {};
|
|
2645
|
+
content2 = typeof message.content === "string" ? message.content : "";
|
|
2646
|
+
for (const candidate of Array.isArray(message.tool_calls) ? message.tool_calls : []) {
|
|
2647
|
+
const call = record7(candidate);
|
|
2648
|
+
const fn = record7(call?.function);
|
|
2649
|
+
if (typeof call?.id !== "string" || typeof fn?.name !== "string" || typeof fn.arguments !== "string") continue;
|
|
2650
|
+
let args;
|
|
2651
|
+
try {
|
|
2652
|
+
args = JSON.parse(fn.arguments);
|
|
2653
|
+
} catch {
|
|
2654
|
+
throw new TypeError("OpenAI-compatible tool arguments are not valid JSON");
|
|
2655
|
+
}
|
|
2656
|
+
toolCalls.push({ id: call.id, name: fn.name, args });
|
|
2657
|
+
}
|
|
2658
|
+
const values = record7(source.usage) ?? {};
|
|
2659
|
+
usage = {
|
|
2660
|
+
input: integer2(values.prompt_tokens),
|
|
2661
|
+
output: integer2(values.completion_tokens),
|
|
2662
|
+
cached: integer2(record7(values.prompt_tokens_details)?.cached_tokens),
|
|
2663
|
+
...costMetadata(values)
|
|
2664
|
+
};
|
|
2665
|
+
} else throw new TypeError("model gateway protocol is invalid");
|
|
2666
|
+
if (!content2 && toolCalls.length === 0) throw new TypeError("model gateway response had no content or Tool calls");
|
|
2667
|
+
return { content: content2, ...toolCalls.length ? { toolCalls } : {}, usage, provider, model };
|
|
2668
|
+
}
|
|
2669
|
+
|
|
2381
2670
|
// src/gateway.ts
|
|
2382
2671
|
async function checkpointArtifactRef(value) {
|
|
2383
2672
|
return await sha256Hex(canonicalJson(value));
|
|
@@ -2655,11 +2944,6 @@ function trainingProvider(definition) {
|
|
|
2655
2944
|
}
|
|
2656
2945
|
});
|
|
2657
2946
|
}
|
|
2658
|
-
var MODEL_COMPLETION_CAPABILITY = {
|
|
2659
|
-
id: "constal.model-completion",
|
|
2660
|
-
version: "1",
|
|
2661
|
-
hash: "0155be6df18b64e7f91ce9939b3c18527813f3dd06260fe65821ed071d94516a"
|
|
2662
|
-
};
|
|
2663
2947
|
var MODEL_CHECKPOINT_IMPORT_CAPABILITY = {
|
|
2664
2948
|
id: "constal.model-checkpoint-import",
|
|
2665
2949
|
version: "1",
|
|
@@ -2898,165 +3182,6 @@ function credentialProvider(definition) {
|
|
|
2898
3182
|
return Object.freeze({ ...definition, mintRecovery, metadata: metadata2 });
|
|
2899
3183
|
}
|
|
2900
3184
|
|
|
2901
|
-
// src/model.ts
|
|
2902
|
-
var NAME4 = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
|
|
2903
|
-
var HEADER = /^[a-z0-9][a-z0-9-]{0,63}$/u;
|
|
2904
|
-
var RESERVED_HEADERS = /* @__PURE__ */ new Set(["connection", "content-type", "host", "anthropic-version", "proxy-authorization", "transfer-encoding"]);
|
|
2905
|
-
function record7(value) {
|
|
2906
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
2907
|
-
}
|
|
2908
|
-
function credentialHeader(value, name) {
|
|
2909
|
-
if (value === null || value === void 0) return null;
|
|
2910
|
-
const source = record7(value);
|
|
2911
|
-
if (!source || typeof source.slot !== "string" || !NAME4.test(source.slot) || typeof source.header !== "string" || !HEADER.test(source.header.toLowerCase()) || RESERVED_HEADERS.has(source.header.toLowerCase()) || source.header.toLowerCase().startsWith("cf-") || source.scheme !== "bearer" && source.scheme !== "raw") throw new TypeError(`${name} is invalid`);
|
|
2912
|
-
return { slot: source.slot, header: source.header.toLowerCase(), scheme: source.scheme };
|
|
2913
|
-
}
|
|
2914
|
-
function normalizeModelGatewayConfig(value) {
|
|
2915
|
-
const source = record7(value);
|
|
2916
|
-
if (!source || typeof source.baseUrl !== "string" || source.baseUrl.length > 2048 || source.protocol !== "anthropic" && source.protocol !== "openai" || typeof source.model !== "string" || source.model.length === 0 || source.model.length > 256) {
|
|
2917
|
-
throw new TypeError("model gateway config is invalid");
|
|
2918
|
-
}
|
|
2919
|
-
const maxOutputTokens = source.maxOutputTokens === void 0 ? 256 : Number(source.maxOutputTokens);
|
|
2920
|
-
const temperature = source.temperature === void 0 ? null : Number(source.temperature);
|
|
2921
|
-
if (!Number.isSafeInteger(maxOutputTokens) || maxOutputTokens < 1 || maxOutputTokens > 8192 || temperature !== null && (!Number.isFinite(temperature) || temperature < 0 || temperature > 2)) {
|
|
2922
|
-
throw new TypeError("model gateway generation limits are invalid");
|
|
2923
|
-
}
|
|
2924
|
-
const normalized = {
|
|
2925
|
-
baseUrl: source.baseUrl,
|
|
2926
|
-
protocol: source.protocol,
|
|
2927
|
-
model: source.model,
|
|
2928
|
-
maxOutputTokens,
|
|
2929
|
-
temperature,
|
|
2930
|
-
gatewayAuth: credentialHeader(source.gatewayAuth, "gatewayAuth"),
|
|
2931
|
-
providerAuth: credentialHeader(source.providerAuth, "providerAuth")
|
|
2932
|
-
};
|
|
2933
|
-
if (normalized.gatewayAuth && normalized.providerAuth && normalized.gatewayAuth.header === normalized.providerAuth.header) {
|
|
2934
|
-
throw new TypeError("gateway and provider credentials cannot share one header");
|
|
2935
|
-
}
|
|
2936
|
-
if (normalized.gatewayAuth && normalized.providerAuth && normalized.gatewayAuth.slot === normalized.providerAuth.slot) {
|
|
2937
|
-
throw new TypeError("gateway and provider credentials cannot share one slot");
|
|
2938
|
-
}
|
|
2939
|
-
modelGatewayEndpoint(normalized);
|
|
2940
|
-
return normalized;
|
|
2941
|
-
}
|
|
2942
|
-
function modelGatewayEndpoint(config) {
|
|
2943
|
-
let endpoint;
|
|
2944
|
-
try {
|
|
2945
|
-
endpoint = new URL(config.baseUrl);
|
|
2946
|
-
} catch {
|
|
2947
|
-
throw new TypeError("model gateway baseUrl is invalid");
|
|
2948
|
-
}
|
|
2949
|
-
if (endpoint.protocol !== "https:" || endpoint.username || endpoint.password || endpoint.search || endpoint.hash) {
|
|
2950
|
-
throw new TypeError("model gateway baseUrl must be a credential-free HTTPS URL");
|
|
2951
|
-
}
|
|
2952
|
-
const hostname = endpoint.hostname.toLowerCase();
|
|
2953
|
-
if (hostname === "localhost" || hostname.endsWith(".localhost") || hostname.endsWith(".local") || hostname.endsWith(".internal")) {
|
|
2954
|
-
throw new TypeError("model gateway baseUrl must use a public hostname");
|
|
2955
|
-
}
|
|
2956
|
-
const suffix = config.protocol === "anthropic" ? "v1/messages" : config.protocol === "openai" ? "v1/chat/completions" : null;
|
|
2957
|
-
if (!suffix) throw new TypeError("model gateway protocol is invalid");
|
|
2958
|
-
endpoint.pathname = `${endpoint.pathname.replace(/\/+$/u, "")}/${suffix}`.replace(/^\/+/u, "/");
|
|
2959
|
-
return endpoint;
|
|
2960
|
-
}
|
|
2961
|
-
function modelPrompt(args) {
|
|
2962
|
-
return JSON.stringify({ objective: args.objective ?? null, context: args.context ?? null, feedback: args.feedback ?? [] });
|
|
2963
|
-
}
|
|
2964
|
-
function modelProtocolRequest(protocol, model, maxOutputTokens, temperature, args) {
|
|
2965
|
-
if (args.toolChoice !== void 0 && args.toolChoice !== "auto" && args.toolChoice !== "required") {
|
|
2966
|
-
throw new TypeError("model Tool choice is invalid");
|
|
2967
|
-
}
|
|
2968
|
-
if (args.toolChoice === "required" && !args.tools?.length) {
|
|
2969
|
-
throw new TypeError("required model Tool choice needs at least one offered Tool");
|
|
2970
|
-
}
|
|
2971
|
-
const prompt = modelPrompt(args);
|
|
2972
|
-
if (protocol === "anthropic") return {
|
|
2973
|
-
model,
|
|
2974
|
-
system: args.system ?? "",
|
|
2975
|
-
messages: [{ role: "user", content: prompt }],
|
|
2976
|
-
max_tokens: maxOutputTokens,
|
|
2977
|
-
...temperature === null ? {} : { temperature },
|
|
2978
|
-
...args.tools?.length ? { tools: args.tools.map((tool) => ({ name: tool.name, description: tool.description, input_schema: tool.schema })) } : {},
|
|
2979
|
-
...args.toolChoice === void 0 ? {} : { tool_choice: { type: args.toolChoice === "required" ? "any" : "auto" } }
|
|
2980
|
-
};
|
|
2981
|
-
if (protocol === "openai") return {
|
|
2982
|
-
model,
|
|
2983
|
-
messages: [
|
|
2984
|
-
...args.system ? [{ role: "developer", content: args.system }] : [],
|
|
2985
|
-
{ role: "user", content: prompt }
|
|
2986
|
-
],
|
|
2987
|
-
max_completion_tokens: maxOutputTokens,
|
|
2988
|
-
...temperature === null ? {} : { temperature },
|
|
2989
|
-
...args.tools?.length ? { tools: args.tools.map((tool) => ({
|
|
2990
|
-
type: "function",
|
|
2991
|
-
function: { name: tool.name, description: tool.description, parameters: tool.schema }
|
|
2992
|
-
})) } : {},
|
|
2993
|
-
...args.toolChoice === void 0 ? {} : { tool_choice: args.toolChoice }
|
|
2994
|
-
};
|
|
2995
|
-
throw new TypeError("model gateway protocol is invalid");
|
|
2996
|
-
}
|
|
2997
|
-
function integer2(value) {
|
|
2998
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
2999
|
-
}
|
|
3000
|
-
function costMetadata(usage) {
|
|
3001
|
-
const cost = usage.cost;
|
|
3002
|
-
const costUsd = cost === null ? null : typeof cost === "number" && Number.isFinite(cost) && cost >= 0 ? cost : void 0;
|
|
3003
|
-
return {
|
|
3004
|
-
...costUsd !== void 0 ? { costUsd } : {},
|
|
3005
|
-
...typeof usage.cost_source === "string" ? { costSource: usage.cost_source } : {},
|
|
3006
|
-
...typeof usage.cost_estimated === "boolean" ? { costEstimated: usage.cost_estimated } : {}
|
|
3007
|
-
};
|
|
3008
|
-
}
|
|
3009
|
-
function modelProtocolResult(protocol, raw, provider, model) {
|
|
3010
|
-
const source = record7(raw) ?? {};
|
|
3011
|
-
const toolCalls = [];
|
|
3012
|
-
let content2 = "";
|
|
3013
|
-
let usage;
|
|
3014
|
-
if (protocol === "anthropic") {
|
|
3015
|
-
const blocks = Array.isArray(source.content) ? source.content : [];
|
|
3016
|
-
content2 = blocks.map((candidate) => {
|
|
3017
|
-
const block = record7(candidate);
|
|
3018
|
-
if (block?.type === "text" && typeof block.text === "string") return block.text;
|
|
3019
|
-
if (block?.type === "tool_use" && typeof block.id === "string" && typeof block.name === "string") {
|
|
3020
|
-
toolCalls.push({ id: block.id, name: block.name, args: block.input ?? {} });
|
|
3021
|
-
}
|
|
3022
|
-
return "";
|
|
3023
|
-
}).join("");
|
|
3024
|
-
const values = record7(source.usage) ?? {};
|
|
3025
|
-
const cached = integer2(values.cache_read_input_tokens);
|
|
3026
|
-
usage = {
|
|
3027
|
-
input: integer2(values.input_tokens) + integer2(values.cache_creation_input_tokens) + cached,
|
|
3028
|
-
output: integer2(values.output_tokens),
|
|
3029
|
-
cached,
|
|
3030
|
-
...costMetadata(values)
|
|
3031
|
-
};
|
|
3032
|
-
} else if (protocol === "openai") {
|
|
3033
|
-
const choice = record7(Array.isArray(source.choices) ? source.choices[0] : null) ?? {};
|
|
3034
|
-
const message = record7(choice.message) ?? {};
|
|
3035
|
-
content2 = typeof message.content === "string" ? message.content : "";
|
|
3036
|
-
for (const candidate of Array.isArray(message.tool_calls) ? message.tool_calls : []) {
|
|
3037
|
-
const call = record7(candidate);
|
|
3038
|
-
const fn = record7(call?.function);
|
|
3039
|
-
if (typeof call?.id !== "string" || typeof fn?.name !== "string" || typeof fn.arguments !== "string") continue;
|
|
3040
|
-
let args;
|
|
3041
|
-
try {
|
|
3042
|
-
args = JSON.parse(fn.arguments);
|
|
3043
|
-
} catch {
|
|
3044
|
-
throw new TypeError("OpenAI-compatible tool arguments are not valid JSON");
|
|
3045
|
-
}
|
|
3046
|
-
toolCalls.push({ id: call.id, name: fn.name, args });
|
|
3047
|
-
}
|
|
3048
|
-
const values = record7(source.usage) ?? {};
|
|
3049
|
-
usage = {
|
|
3050
|
-
input: integer2(values.prompt_tokens),
|
|
3051
|
-
output: integer2(values.completion_tokens),
|
|
3052
|
-
cached: integer2(record7(values.prompt_tokens_details)?.cached_tokens),
|
|
3053
|
-
...costMetadata(values)
|
|
3054
|
-
};
|
|
3055
|
-
} else throw new TypeError("model gateway protocol is invalid");
|
|
3056
|
-
if (!content2 && toolCalls.length === 0) throw new TypeError("model gateway response had no content or Tool calls");
|
|
3057
|
-
return { content: content2, ...toolCalls.length ? { toolCalls } : {}, usage, provider, model };
|
|
3058
|
-
}
|
|
3059
|
-
|
|
3060
3185
|
// src/scorer.ts
|
|
3061
3186
|
function validPointer(value) {
|
|
3062
3187
|
return typeof value === "string" && value.length <= 4096 && (value === "" || value.startsWith("/") && !/~(?:[^01]|$)/u.test(value));
|
|
@@ -3509,6 +3634,7 @@ export {
|
|
|
3509
3634
|
scorerName,
|
|
3510
3635
|
selectableResourceLabels,
|
|
3511
3636
|
setupAwait,
|
|
3637
|
+
setupCredentialReceipt,
|
|
3512
3638
|
setupScreen,
|
|
3513
3639
|
setupScreenView,
|
|
3514
3640
|
setupSubmission,
|