@opengeni/codemode 0.2.2

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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Cloudgeni-ai
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # `@opengeni/codemode`
2
+
3
+ OpenGeni's canonical attempt-frozen programmatic tool surface. It compiles one
4
+ catalog from the exact tools admitted to an execution attempt and dispatches
5
+ both model MCP calls and sandbox Codemode calls through the same opaque tool
6
+ identities and executors.
7
+
8
+ The package owns deterministic catalog projection, collision-safe JavaScript
9
+ paths, catalog digests, stale-catalog fencing, approval classification, and
10
+ result-shape preservation. It does not discover MCP servers, resolve
11
+ credentials, persist attempts, or bypass host authorization; callers provide
12
+ the already-admitted definitions and one authorization hook.
13
+
14
+ `modelName` and `codemodePath` are projections only. Execution authority is
15
+ always the exact `{ serverId, toolName }` identity in the frozen catalog.
16
+
17
+ Inside an OpenGeni sandbox the worker supplies `OPENGENI_CODEMODE_URL` and a
18
+ renewed bearer file. The package exposes one lazy namespace over that exact
19
+ attempt catalog:
20
+
21
+ ```ts
22
+ import { tools } from "@opengeni/codemode";
23
+
24
+ const sessions = await tools.opengeni.sessions_list({ status: "running" });
25
+ const hits = await tools.slack.search({ query: "release blocker" });
26
+ ```
27
+
28
+ Generate digest-pinned project declarations from the live attempt catalog with
29
+ `ogtool declarations opengeni-codemode.d.ts`. Runtime schema validation remains
30
+ authoritative when a script outlives a catalog generation.
31
+
32
+ The bearer is reread for every request. Namespace paths are resolved against
33
+ the signed catalog and never parsed into authority from flattened model names.
34
+ For Browser/Computer work, the authored facade wraps those same atomic entries:
35
+
36
+ ```ts
37
+ import { openGeni } from "@opengeni/codemode";
38
+
39
+ const browser = await openGeni.browsers.open({ initialUrl: "http://127.0.0.1:3000" });
40
+ const tab = await browser.tabs.selected();
41
+ await tab.getByRole("button", { name: "Save" }).click();
42
+
43
+ const computer = await openGeni.computers.open();
44
+ const app = await computer.apps.focused();
45
+ await app.getByRole("button", { name: "1" }).invoke();
46
+ ```
47
+
48
+ Both surfaces return the same durable tool receipts. Human approval, catalog
49
+ generation, operation idempotency, and outcome-unknown behavior remain enforced
50
+ by the shared attempt executor.
51
+
52
+ Editable artifacts use the same path. The object remains in OpenGeni; files are
53
+ only explicit import/export boundaries:
54
+
55
+ ```ts
56
+ import { openGeni } from "@opengeni/codemode";
57
+
58
+ const workbook = await openGeni.artifacts.create("spreadsheet", "Forecast");
59
+ const sheetId = openGeni.artifacts.ids.stable();
60
+ await workbook.apply([
61
+ { kind: "sheet.create", sheetId, name: "Inputs", after: null },
62
+ {
63
+ kind: "cells.set",
64
+ sheet: { kind: "created-in-batch", sheetId, createCommandIndex: 0 },
65
+ anchor: { row: 0, column: 0 },
66
+ rows: 2,
67
+ columns: 2,
68
+ cells: ["Metric", "Value", "Revenue", 120],
69
+ },
70
+ ]);
71
+ ```
@@ -0,0 +1,99 @@
1
+ import type { DocumentArtifactId, DocumentArtifactIdKind, DocumentArtifactCommand, DocumentArtifactQuery, EditableArtifactStableId, PresentationArtifactCommand, PresentationArtifactQuery, SpreadsheetArtifactCommand, SpreadsheetArtifactKernelQuery } from "@opengeni/contracts/editable-artifacts";
2
+ import type { CodemodeCallOptions } from "./index.js";
3
+ import type { CodemodeClientProvider } from "./environment.js";
4
+ export type CodemodeArtifactModality = "spreadsheet" | "document" | "presentation";
5
+ export type CodemodeArtifactFormat = "xlsx" | "pptx" | "docx" | "pdf" | "png" | "webp";
6
+ export type CodemodeArtifactMetadata = Readonly<{
7
+ id: string;
8
+ modality: CodemodeArtifactModality;
9
+ title: string;
10
+ lifecycle: "active" | "archived";
11
+ headSequence: number;
12
+ stateHash: string;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ }>;
16
+ export type CodemodeArtifactQuery = SpreadsheetArtifactKernelQuery | DocumentArtifactQuery | PresentationArtifactQuery;
17
+ export type CodemodeArtifactCommand = SpreadsheetArtifactCommand | DocumentArtifactCommand | PresentationArtifactCommand;
18
+ export type CodemodeArtifactMutationReceipt = Readonly<{
19
+ artifact: CodemodeArtifactMetadata;
20
+ transaction: Readonly<{
21
+ id: string;
22
+ clientTransactionId: string;
23
+ sequenceStart: number;
24
+ sequenceEnd: number;
25
+ stateHash: string;
26
+ committedAt: string;
27
+ replayed: boolean;
28
+ }>;
29
+ }>;
30
+ export type CodemodeArtifactExportFile = Readonly<{
31
+ fileId: string;
32
+ filename: string;
33
+ contentType: string;
34
+ sizeBytes: number;
35
+ sha256: string;
36
+ artifactId: string;
37
+ versionId: string;
38
+ materializationJobId: string;
39
+ sourceHeadSequence: number;
40
+ sourceStateHash: string;
41
+ }>;
42
+ export type CodemodeArtifactExportStatus = Readonly<{
43
+ artifact: CodemodeArtifactMetadata;
44
+ versionId: string;
45
+ jobId: string;
46
+ sourceHeadSequence: number;
47
+ sourceStateHash: string;
48
+ state: "pending" | "running" | "succeeded" | "failed";
49
+ errorCode: string | null;
50
+ file: CodemodeArtifactExportFile | null;
51
+ }>;
52
+ export type CodemodeArtifactIdFactory = Readonly<{
53
+ /** Create a nonzero 128-bit id accepted by spreadsheet and presentation commands. */
54
+ stable(): EditableArtifactStableId;
55
+ /** Create a document object id in the namespace returned by a summary query. */
56
+ document(kind: DocumentArtifactIdKind, namespace: bigint | number | string): DocumentArtifactId;
57
+ }>;
58
+ export declare const codemodeArtifactIds: CodemodeArtifactIdFactory;
59
+ /** Authored CodeMode collection over the exact MCP-backed artifact operations. */
60
+ export declare class CodemodeArtifactCollection {
61
+ private readonly client;
62
+ readonly ids: Readonly<{
63
+ /** Create a nonzero 128-bit id accepted by spreadsheet and presentation commands. */
64
+ stable(): EditableArtifactStableId;
65
+ /** Create a document object id in the namespace returned by a summary query. */
66
+ document(kind: DocumentArtifactIdKind, namespace: bigint | number | string): DocumentArtifactId;
67
+ }>;
68
+ constructor(client: CodemodeClientProvider);
69
+ list(options?: {
70
+ limit?: number | undefined;
71
+ }, callOptions?: CodemodeCallOptions): Promise<CodemodeArtifactMetadata[]>;
72
+ create(modality: CodemodeArtifactModality, title: string, callOptions?: CodemodeCallOptions): Promise<CodemodeArtifact>;
73
+ import(fileId: string, modality: CodemodeArtifactModality, title: string, callOptions?: CodemodeCallOptions): Promise<CodemodeArtifact>;
74
+ use(artifact: string | CodemodeArtifactMetadata): CodemodeArtifact;
75
+ }
76
+ export declare class CodemodeArtifact {
77
+ private readonly client;
78
+ readonly id: string;
79
+ private metadata;
80
+ constructor(client: CodemodeClientProvider, id: string, metadata?: CodemodeArtifactMetadata | null);
81
+ get(callOptions?: CodemodeCallOptions): Promise<CodemodeArtifactMetadata>;
82
+ inspect<T = unknown>(query: CodemodeArtifactQuery, callOptions?: CodemodeCallOptions): Promise<Readonly<{
83
+ artifact: CodemodeArtifactMetadata;
84
+ projection: T;
85
+ }>>;
86
+ apply(commands: readonly CodemodeArtifactCommand[], callOptions?: CodemodeCallOptions): Promise<CodemodeArtifactMutationReceipt>;
87
+ export(format: CodemodeArtifactFormat, options?: Readonly<Record<string, unknown>>, callOptions?: CodemodeCallOptions): Promise<CodemodeArtifactExport>;
88
+ private currentMetadata;
89
+ }
90
+ export declare class CodemodeArtifactExport {
91
+ private readonly client;
92
+ readonly artifactId: string;
93
+ readonly versionId: string;
94
+ readonly jobId: string;
95
+ readonly sourceHeadSequence: number;
96
+ readonly sourceStateHash: string;
97
+ constructor(client: CodemodeClientProvider, artifactId: string, versionId: string, jobId: string, sourceHeadSequence: number, sourceStateHash: string);
98
+ status(callOptions?: CodemodeCallOptions): Promise<CodemodeArtifactExportStatus>;
99
+ }
@@ -0,0 +1,12 @@
1
+ import type { AttemptToolCatalog } from "@opengeni/contracts";
2
+ export type GenerateCodemodeDeclarationsOptions = {
3
+ /** Package whose augmentable CodemodeGeneratedTools interface owns the namespace. */
4
+ moduleSpecifier?: string;
5
+ };
6
+ /**
7
+ * Generate declaration merging for one exact, digest-pinned attempt catalog.
8
+ * Types improve authoring only; runtime catalog validation remains authoritative.
9
+ */
10
+ export declare function generateCodemodeDeclarations(catalog: AttemptToolCatalog, options?: GenerateCodemodeDeclarationsOptions): string;
11
+ /** Honest JSON-Schema-to-TypeScript projection used by declaration generation. */
12
+ export declare function jsonSchemaToTypeScript(schema: unknown): string;
@@ -0,0 +1,28 @@
1
+ import { CodemodeClient, type CodemodeToolFunction } from "./index.js";
2
+ export declare const CODEMODE_ENVIRONMENT: {
3
+ readonly url: "OPENGENI_CODEMODE_URL";
4
+ readonly tokenFile: "OPENGENI_CODEMODE_TOKEN_FILE";
5
+ };
6
+ export type CodemodeClientProvider = () => CodemodeClient | Promise<CodemodeClient>;
7
+ /** A lazy catalog path. Every nested property remains callable at runtime. */
8
+ export type CodemodeDynamicTool = CodemodeToolFunction & {
9
+ readonly [segment: string]: CodemodeDynamicTool;
10
+ };
11
+ export type CodemodeDynamicTools = {
12
+ readonly [segment: string]: CodemodeDynamicTool;
13
+ };
14
+ /** Catalog-specific generated declarations augment this interface. */
15
+ export interface CodemodeGeneratedTools {
16
+ }
17
+ export type CodemodeToolsNamespace = CodemodeDynamicTools & CodemodeGeneratedTools;
18
+ /**
19
+ * Build (or reuse) the persistent client for the exact sandbox attempt.
20
+ * The bearer file is reread for every HTTP request so worker renewal is live.
21
+ */
22
+ export declare function environmentCodemodeClient(environment?: NodeJS.ProcessEnv): CodemodeClient;
23
+ /**
24
+ * Lazy namespace used by ordinary sandbox programs:
25
+ * `await tools.slack.search({ query: "..." })`.
26
+ */
27
+ export declare function createCodemodeTools(client?: CodemodeClientProvider): CodemodeToolsNamespace;
28
+ export declare const tools: CodemodeToolsNamespace;
@@ -0,0 +1,161 @@
1
+ import { type ValidateFunction } from "ajv";
2
+ import { type AttemptToolCall as AttemptToolCallValue, type AttemptToolCaller, type AttemptToolCatalog as AttemptToolCatalogValue, type AttemptToolCatalogEntry as AttemptToolCatalogEntryValue, type AttemptToolIdentity, type AttemptToolResult as AttemptToolResultValue, type CodemodeDispatchAck as CodemodeDispatchAckValue, type CodemodeDispatchRequest as CodemodeDispatchRequestValue, type CodemodeOperation as CodemodeOperationValue } from "@opengeni/contracts";
3
+ export type { AttemptToolCatalog, AttemptToolCatalogEntry } from "@opengeni/contracts";
4
+ export type AttemptToolScope = Pick<AttemptToolCatalogValue, "accountId" | "workspaceId" | "sessionId" | "turnId" | "attemptId" | "executionGeneration">;
5
+ export type AttemptToolExecutionContext = {
6
+ operationId: string;
7
+ caller: AttemptToolCaller;
8
+ /** In-process transport metadata; never part of catalog identity or digest. */
9
+ transportMeta?: Record<string, unknown> | null;
10
+ signal?: AbortSignal;
11
+ };
12
+ export type AttemptToolDefinition = Omit<AttemptToolCatalogEntryValue, "codemodePath"> & {
13
+ /** Optional human-readable path. Unsafe/colliding segments are normalized. */
14
+ codemodePath?: readonly string[];
15
+ execute: (args: Record<string, unknown>, context: AttemptToolExecutionContext) => Promise<AttemptToolResultValue> | AttemptToolResultValue;
16
+ };
17
+ export type AttemptToolAuthorization = (input: {
18
+ call: AttemptToolCallValue;
19
+ entry: AttemptToolCatalogEntryValue;
20
+ }) => Promise<void> | void;
21
+ export type CreateAttemptToolEnvironmentInput = {
22
+ scope: AttemptToolScope;
23
+ generation: number;
24
+ definitions: readonly AttemptToolDefinition[];
25
+ createdAt?: Date;
26
+ authorize?: AttemptToolAuthorization;
27
+ };
28
+ export type ModelAttemptToolCall = {
29
+ operationId?: string;
30
+ modelName: string;
31
+ arguments: Record<string, unknown>;
32
+ subjectId: string;
33
+ transportMeta?: Record<string, unknown> | null;
34
+ signal?: AbortSignal;
35
+ };
36
+ export declare class AttemptToolCatalogStaleError extends Error {
37
+ readonly code = "catalog_stale";
38
+ constructor();
39
+ }
40
+ export declare class AttemptToolNotFoundError extends Error {
41
+ readonly code = "tool_not_found";
42
+ constructor();
43
+ }
44
+ export declare class AttemptToolApprovalRequiredError extends Error {
45
+ readonly code = "approval_required";
46
+ constructor();
47
+ }
48
+ export declare class AttemptToolCatalogIntegrityError extends Error {
49
+ readonly code = "catalog_integrity_failed";
50
+ constructor();
51
+ }
52
+ export declare class AttemptToolCatalogTooLargeError extends Error {
53
+ readonly code = "catalog_too_large";
54
+ constructor();
55
+ }
56
+ export declare class AttemptToolInputValidationError extends Error {
57
+ readonly code = "invalid_tool_arguments";
58
+ constructor();
59
+ }
60
+ export declare class AttemptToolOutputValidationError extends Error {
61
+ readonly code = "invalid_tool_result";
62
+ constructor();
63
+ }
64
+ export declare class CodemodeTransportError extends Error {
65
+ readonly status: number | null;
66
+ readonly code = "codemode_transport_error";
67
+ constructor(message: string, status?: number | null);
68
+ }
69
+ export declare class CodemodeOperationError extends Error {
70
+ readonly operation: CodemodeOperationValue;
71
+ readonly code: string;
72
+ constructor(operation: CodemodeOperationValue, code: string);
73
+ }
74
+ export type CodemodeTokenProvider = string | (() => string | Promise<string>);
75
+ export type CodemodeClientOptions = {
76
+ /** `/v1/workspaces/:workspaceId/codemode` base URL. */
77
+ baseUrl: string;
78
+ token: CodemodeTokenProvider;
79
+ fetch?: typeof globalThis.fetch;
80
+ pollIntervalMs?: number;
81
+ timeoutMs?: number;
82
+ };
83
+ export type CodemodeCallOptions = {
84
+ operationId?: string;
85
+ signal?: AbortSignal;
86
+ timeoutMs?: number;
87
+ };
88
+ export type CodemodeToolFunction = (argumentsValue?: Record<string, unknown>, options?: CodemodeCallOptions) => Promise<unknown>;
89
+ export type CodemodeToolResult = AttemptToolResultValue;
90
+ export declare class CodemodeToolCallError extends Error {
91
+ readonly result: AttemptToolResultValue;
92
+ readonly code: string;
93
+ readonly retryable: boolean;
94
+ constructor(result: AttemptToolResultValue);
95
+ }
96
+ export declare class CodemodeToolContractError extends Error {
97
+ readonly code = "invalid_tool_result";
98
+ constructor(message: string);
99
+ }
100
+ export interface CodemodeTools {
101
+ [key: string]: CodemodeTools | CodemodeToolFunction;
102
+ }
103
+ /** Persistent, idempotent client for one exact sandbox attempt bearer. */
104
+ export declare class CodemodeClient {
105
+ private readonly options;
106
+ private readonly baseUrl;
107
+ private readonly fetchImpl;
108
+ private readonly pollIntervalMs;
109
+ private readonly timeoutMs;
110
+ private catalogSnapshot;
111
+ constructor(options: CodemodeClientOptions);
112
+ catalog(options?: {
113
+ refresh?: boolean;
114
+ signal?: AbortSignal;
115
+ }): Promise<AttemptToolCatalogValue>;
116
+ tools(options?: {
117
+ refresh?: boolean;
118
+ signal?: AbortSignal;
119
+ }): Promise<CodemodeTools>;
120
+ call(identity: AttemptToolIdentity, argumentsValue?: Record<string, unknown>, options?: CodemodeCallOptions): Promise<AttemptToolResultValue>;
121
+ /** Resolve and call one exact generated namespace path without parsing a wire name. */
122
+ callPath(path: readonly string[], argumentsValue?: Record<string, unknown>, options?: CodemodeCallOptions): Promise<AttemptToolResultValue>;
123
+ /** Return structured content when the catalog declares it; otherwise retain the full MCP result. */
124
+ callPathValue(path: readonly string[], argumentsValue?: Record<string, unknown>, options?: CodemodeCallOptions): Promise<unknown>;
125
+ private submit;
126
+ private read;
127
+ private request;
128
+ }
129
+ export declare function compileCodemodeTools(catalog: AttemptToolCatalogValue, client: CodemodeClient): CodemodeTools;
130
+ type CompiledDefinition = {
131
+ entry: AttemptToolCatalogEntryValue;
132
+ execute: AttemptToolDefinition["execute"];
133
+ validateInput: ValidateFunction<unknown>;
134
+ validateOutput: ValidateFunction<unknown> | null;
135
+ };
136
+ export declare class AttemptToolEnvironment {
137
+ private readonly authorize;
138
+ readonly catalog: AttemptToolCatalogValue;
139
+ private readonly byIdentity;
140
+ private readonly byModelName;
141
+ constructor(catalog: AttemptToolCatalogValue, definitions: readonly CompiledDefinition[], authorize: AttemptToolAuthorization | undefined);
142
+ call(input: AttemptToolCallValue, context?: {
143
+ transportMeta?: Record<string, unknown> | null;
144
+ signal?: AbortSignal;
145
+ }): Promise<AttemptToolResultValue>;
146
+ callModel(input: ModelAttemptToolCall): Promise<AttemptToolResultValue>;
147
+ }
148
+ export declare function createAttemptToolEnvironment(input: CreateAttemptToolEnvironmentInput): AttemptToolEnvironment;
149
+ export declare function digestAttemptToolCatalog(catalog: Omit<AttemptToolCatalogValue, "digest">): string;
150
+ export declare function digestCodemodeOperationRequest(input: Pick<AttemptToolCallValue, "catalogDigest" | "identity" | "arguments" | "caller">): string;
151
+ export declare function codemodeDispatchSubject(workspaceId: string, attemptId: string): string;
152
+ export declare function encodeCodemodeDispatchRequest(input: CodemodeDispatchRequestValue): Uint8Array;
153
+ export declare function decodeCodemodeDispatchRequest(input: Uint8Array): CodemodeDispatchRequestValue;
154
+ export declare function encodeCodemodeDispatchAck(input: CodemodeDispatchAckValue): Uint8Array;
155
+ export declare function decodeCodemodeDispatchAck(input: Uint8Array): CodemodeDispatchAckValue;
156
+ export declare function parseVerifiedAttemptToolCatalog(input: unknown): AttemptToolCatalogValue;
157
+ export * from "./environment.js";
158
+ export * from "./interaction.js";
159
+ export * from "./artifacts.js";
160
+ export * from "./structured.js";
161
+ export * from "./declarations.js";