@tryvira/sdk 0.1.75 → 0.1.94

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.
@@ -0,0 +1,42 @@
1
+ import type { CompletionHostRequest, HostCompletionTool, HostEffectResult } from './host-completion.ts';
2
+ type Args = Parameters<HostCompletionTool['execute']>[0]['arguments'];
3
+ type Recover = NonNullable<HostCompletionTool['recover']>;
4
+ type ResultDecoder = (value: unknown, request: CompletionHostRequest) => HostEffectResult | Promise<HostEffectResult>;
5
+ /** Explicit domain result, not the transport call ID or a success flag.
6
+ * Applications may supply a decoder to extract their real provider receipt. */
7
+ export declare function decodeHostEffectResult(value: unknown): HostEffectResult;
8
+ export type CompletionMcpClient = {
9
+ callTool(input: {
10
+ name: string;
11
+ arguments: Record<string, unknown>;
12
+ _meta?: Record<string, unknown>;
13
+ }, resultSchema?: undefined, options?: {
14
+ signal?: AbortSignal;
15
+ }): Promise<unknown>;
16
+ };
17
+ /** Bridge an already-connected, authenticated MCP client. Only one pinned
18
+ * tool can be invoked, with the approved arguments unchanged. MCP transport
19
+ * success is not proof of the effect: require domain result evidence.
20
+ * Never use a generic Vira observation or an untrusted model output here. */
21
+ export declare function createMcpHostCompletionTool(input: {
22
+ client: CompletionMcpClient;
23
+ toolKey: string;
24
+ mcpToolName?: string;
25
+ decode?: ResultDecoder;
26
+ recover?: Recover;
27
+ }): HostCompletionTool;
28
+ /** Bridge an application-owned OpenCode custom tool implementation.
29
+ * The caller supplies a real registered callable, NOT an execute.after event,
30
+ * an arbitrary shell command or a client-supplied success receipt. This can
31
+ * run in a dedicated host sidecar without the interactive model session. */
32
+ export declare function createOpenCodeHostCompletionTool(input: {
33
+ toolKey: string;
34
+ invoke: (args: Args, context: {
35
+ idempotencyKey: string;
36
+ request: CompletionHostRequest;
37
+ signal?: AbortSignal;
38
+ }) => Promise<unknown>;
39
+ decode?: ResultDecoder;
40
+ recover?: Recover;
41
+ }): HostCompletionTool;
42
+ export {};
@@ -0,0 +1,14 @@
1
+ import { type HostCompletionStore } from './host-completion.ts';
2
+ export type HostCompletionPostgres = {
3
+ query(sql: string, params?: unknown[]): Promise<{
4
+ rows: Record<string, unknown>[];
5
+ rowCount?: number | null;
6
+ }>;
7
+ };
8
+ /** Install once in the CUSTOMER host database, not Vira's control-plane DB.
9
+ * Keep DELETE/UPDATE of admission identity unavailable to the service role.
10
+ * A terminal receipt cannot be rewritten; no time-based replay lease. */
11
+ export declare const HOST_COMPLETION_POSTGRES_SCHEMA = "\nCREATE TABLE IF NOT EXISTS vira_host_completion_v1 (\n invocation_id text PRIMARY KEY,\n binding_digest text NOT NULL CHECK(binding_digest ~ '^[a-f0-9]{64}$'),\n request_digest text NOT NULL CHECK(request_digest ~ '^[a-f0-9]{64}$'),\n request_json text NOT NULL,\n completion_json text,\n completion_digest text CHECK(completion_digest ~ '^[a-f0-9]{64}$'),\n admitted_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,\n completed_at timestamptz,\n CHECK ((completion_json IS NULL AND completion_digest IS NULL AND completed_at IS NULL)\n OR (completion_json IS NOT NULL AND completion_digest IS NOT NULL AND completed_at IS NOT NULL))\n);\nCREATE OR REPLACE FUNCTION vira_host_completion_v1_immutable() RETURNS trigger LANGUAGE plpgsql AS $$\nBEGIN\n IF TG_OP='DELETE' THEN RAISE EXCEPTION 'HOST_COMPLETION_IMMUTABLE'; END IF;\n IF OLD.completion_json IS NOT NULL OR NEW.completion_json IS NULL\n OR NEW.invocation_id IS DISTINCT FROM OLD.invocation_id OR NEW.binding_digest IS DISTINCT FROM OLD.binding_digest\n OR NEW.request_digest IS DISTINCT FROM OLD.request_digest OR NEW.request_json IS DISTINCT FROM OLD.request_json\n OR NEW.admitted_at IS DISTINCT FROM OLD.admitted_at THEN RAISE EXCEPTION 'HOST_COMPLETION_IMMUTABLE'; END IF;\n RETURN NEW;\nEND;\n$$;\nDROP TRIGGER IF EXISTS vira_host_completion_v1_immutable ON vira_host_completion_v1;\nCREATE TRIGGER vira_host_completion_v1_immutable BEFORE UPDATE OR DELETE ON vira_host_completion_v1\n FOR EACH ROW EXECUTE FUNCTION vira_host_completion_v1_immutable();\n";
12
+ /** Requires a pool whose individual query calls commit independently; do not
13
+ * pass a transaction client. Claim must commit before any external I/O. */
14
+ export declare function createPostgresHostCompletionStore(db: HostCompletionPostgres): HostCompletionStore;
@@ -0,0 +1,196 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ type Json = null | boolean | number | string | Json[] | {
3
+ [key: string]: Json;
4
+ };
5
+ export type CompletionHostScope = {
6
+ organizationId: string;
7
+ projectId: string;
8
+ environmentId: string;
9
+ organizationUnitId: string;
10
+ };
11
+ export type CompletionHostRequest = {
12
+ schemaVersion: 1;
13
+ invocationId: string;
14
+ scope: CompletionHostScope;
15
+ aiSystemId: string;
16
+ actorId: string;
17
+ toolKey: string;
18
+ runtimeReceiptId: string;
19
+ authorizationDigest: string;
20
+ argumentsDigest: string;
21
+ bindingDigest: string;
22
+ [key: string]: unknown;
23
+ };
24
+ export type SignedHostCompletion = {
25
+ receipt: {
26
+ schemaVersion: 1;
27
+ status: 'COMPLETED';
28
+ invocationId: string;
29
+ requestDigest: string;
30
+ providerInvocationId: string;
31
+ resultDigest: string;
32
+ };
33
+ signature: string;
34
+ result: Json;
35
+ };
36
+ export type HostCompletionBinding = {
37
+ kind: 'SINGLE' | 'STRATEGY' | 'RECOVERY';
38
+ recoveryPlanDigest?: string;
39
+ recoveryStepType?: 'retry' | 'restore_checkpoint' | 'invoke_compensation_action' | 'cancel_pending' | 'require_approval' | 'escalate' | 'terminate_trajectory';
40
+ scope: CompletionHostScope;
41
+ aiSystemId: string;
42
+ toolKey: string;
43
+ bindingDigest: string;
44
+ dispatchToken: string;
45
+ readbackToken: string;
46
+ receiptKey: string;
47
+ connectionId?: string;
48
+ semanticTaskKey?: string;
49
+ };
50
+ export type HostCompletionRecord = {
51
+ request: CompletionHostRequest;
52
+ requestDigest: string;
53
+ completion: SignedHostCompletion | null;
54
+ };
55
+ export type HostCompletionStore = {
56
+ claim(request: CompletionHostRequest, requestDigest: string): Promise<{
57
+ claimed: boolean;
58
+ record: HostCompletionRecord;
59
+ }>;
60
+ get(invocationId: string, bindingDigest: string): Promise<HostCompletionRecord | null>;
61
+ complete(request: CompletionHostRequest, requestDigest: string, completion: SignedHostCompletion): Promise<HostCompletionRecord>;
62
+ };
63
+ export type HostEffectResult = {
64
+ providerInvocationId: string;
65
+ result: Json;
66
+ };
67
+ export type HostCompletionTool = {
68
+ /** Execute only the registered business operation; forward the stable
69
+ * idempotency key to the actual downstream authority when supported. */
70
+ execute(input: {
71
+ request: CompletionHostRequest;
72
+ arguments: Readonly<Record<string, Json>>;
73
+ idempotencyKey: string;
74
+ signal?: AbortSignal;
75
+ }): Promise<HostEffectResult>;
76
+ /** Optional read-only lookup of a previously executed effect. It must never
77
+ * execute, retry, or infer success from the absence of a provider error. */
78
+ recover?(input: {
79
+ request: CompletionHostRequest;
80
+ idempotencyKey: string;
81
+ }): Promise<HostEffectResult | null>;
82
+ };
83
+ /** Same byte-level ordering as the worker's signed external host ABI. */
84
+ export declare function canonicalHostCompletionJson(v: unknown): string;
85
+ export declare const hostCompletionDigest: (v: unknown) => string;
86
+ export declare function signHostCompletion(request: CompletionHostRequest, requestDigest: string, outcome: HostEffectResult, key: string): SignedHostCompletion;
87
+ /** Derive the exact deployed worker binding digest without copying secrets
88
+ * into configuration files. Endpoint strings are normalized like the worker. */
89
+ export declare function createHostCompletionBinding(input: Omit<HostCompletionBinding, 'bindingDigest'> & {
90
+ endpoint: string;
91
+ receiptEndpoint: string;
92
+ tokenEnv: string;
93
+ receiptTokenEnv: string;
94
+ receiptKeyEnv: string;
95
+ }): HostCompletionBinding;
96
+ /** Durable claim precedes external execution. No retry after an ambiguous
97
+ * outcome. Receipt readback can consult an independent provider lookup only. */
98
+ export declare function createHostCompletionAuthority(input: {
99
+ binding: HostCompletionBinding;
100
+ store: HostCompletionStore;
101
+ tool: HostCompletionTool;
102
+ }): {
103
+ dispatch(input: {
104
+ authorization: unknown;
105
+ idempotencyKey: unknown;
106
+ body: unknown;
107
+ signal?: AbortSignal;
108
+ }): Promise<{
109
+ status: number;
110
+ body: {
111
+ error: string;
112
+ status?: undefined;
113
+ invocationId?: undefined;
114
+ };
115
+ } | {
116
+ status: number;
117
+ body: {
118
+ status: string;
119
+ invocationId: string;
120
+ error?: undefined;
121
+ };
122
+ }>;
123
+ readback(input: {
124
+ authorization: unknown;
125
+ invocationId: unknown;
126
+ }): Promise<{
127
+ status: number;
128
+ body: {
129
+ error: string;
130
+ status?: undefined;
131
+ };
132
+ } | {
133
+ status: number;
134
+ body: SignedHostCompletion;
135
+ } | {
136
+ status: number;
137
+ body: {
138
+ status: string;
139
+ error?: undefined;
140
+ };
141
+ }>;
142
+ capabilities(authorization: unknown): {
143
+ status: number;
144
+ body: {
145
+ schemaVersion: number;
146
+ kind: "SINGLE" | "STRATEGY" | "RECOVERY";
147
+ scope: {
148
+ organizationId: string;
149
+ projectId: string;
150
+ environmentId: string;
151
+ organizationUnitId: string;
152
+ };
153
+ aiSystemId: string;
154
+ toolKey: string;
155
+ bindingDigest: string;
156
+ independentReadback: boolean;
157
+ durableClaimRequired: boolean;
158
+ providerRecovery: boolean;
159
+ error?: undefined;
160
+ };
161
+ } | {
162
+ status: number;
163
+ body: {
164
+ error: string;
165
+ schemaVersion?: undefined;
166
+ kind?: undefined;
167
+ scope?: undefined;
168
+ aiSystemId?: undefined;
169
+ toolKey?: undefined;
170
+ bindingDigest?: undefined;
171
+ independentReadback?: undefined;
172
+ durableClaimRequired?: undefined;
173
+ providerRecovery?: undefined;
174
+ };
175
+ };
176
+ };
177
+ export type HostCompletionAuthority = ReturnType<typeof createHostCompletionAuthority>;
178
+ /** Mount behind TLS on a customer-controlled host. No arbitrary tool names,
179
+ * commands, callback URLs or client-submitted completion receipts. */
180
+ export declare function createHostCompletionHttpHandler(authority: HostCompletionAuthority, paths?: {
181
+ dispatch?: string;
182
+ readback?: string;
183
+ capabilities?: string;
184
+ }): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
185
+ /** Read-only deployment check. Credentials and endpoint configuration must
186
+ * come from the trusted operator, not an end-user request or model output. */
187
+ export declare function checkHostCompletionCapabilities(input: {
188
+ binding: HostCompletionBinding;
189
+ receiptEndpoint: string;
190
+ fetcher?: typeof fetch;
191
+ }): Promise<{
192
+ verified: true;
193
+ bindingDigest: string;
194
+ providerRecovery: boolean;
195
+ }>;
196
+ export {};