@mondaydotcomorg/atp-runtime 0.17.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +389 -0
- package/dist/approval/handler.d.ts +12 -0
- package/dist/approval/handler.d.ts.map +1 -0
- package/dist/approval/handler.js +17 -0
- package/dist/approval/handler.js.map +1 -0
- package/dist/approval/index.d.ts +17 -0
- package/dist/approval/index.d.ts.map +1 -0
- package/dist/approval/index.js +94 -0
- package/dist/approval/index.js.map +1 -0
- package/dist/approval/types.d.ts +21 -0
- package/dist/approval/types.d.ts.map +1 -0
- package/dist/approval/types.js +5 -0
- package/dist/approval/types.js.map +1 -0
- package/dist/cache/backends.d.ts +39 -0
- package/dist/cache/backends.d.ts.map +1 -0
- package/dist/cache/backends.js +167 -0
- package/dist/cache/backends.js.map +1 -0
- package/dist/cache/index.d.ts +32 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +103 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/types.d.ts +20 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +2 -0
- package/dist/cache/types.js.map +1 -0
- package/dist/embedding/index.d.ts +39 -0
- package/dist/embedding/index.d.ts.map +1 -0
- package/dist/embedding/index.js +162 -0
- package/dist/embedding/index.js.map +1 -0
- package/dist/embedding/types.d.ts +28 -0
- package/dist/embedding/types.d.ts.map +1 -0
- package/dist/embedding/types.js +5 -0
- package/dist/embedding/types.js.map +1 -0
- package/dist/embedding/utils.d.ts +11 -0
- package/dist/embedding/utils.d.ts.map +1 -0
- package/dist/embedding/utils.js +30 -0
- package/dist/embedding/utils.js.map +1 -0
- package/dist/embedding/vector-store.d.ts +64 -0
- package/dist/embedding/vector-store.d.ts.map +1 -0
- package/dist/embedding/vector-store.js +142 -0
- package/dist/embedding/vector-store.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/callback.d.ts +13 -0
- package/dist/llm/callback.d.ts.map +1 -0
- package/dist/llm/callback.js +19 -0
- package/dist/llm/callback.js.map +1 -0
- package/dist/llm/index.d.ts +29 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +118 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/replay.d.ts +47 -0
- package/dist/llm/replay.d.ts.map +1 -0
- package/dist/llm/replay.js +114 -0
- package/dist/llm/replay.js.map +1 -0
- package/dist/llm/types.d.ts +24 -0
- package/dist/llm/types.d.ts.map +1 -0
- package/dist/llm/types.js +2 -0
- package/dist/llm/types.js.map +1 -0
- package/dist/log/index.d.ts +12 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/index.js +166 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/types.d.ts +19 -0
- package/dist/log/types.d.ts.map +1 -0
- package/dist/log/types.js +5 -0
- package/dist/log/types.js.map +1 -0
- package/dist/metadata/decorators.d.ts +27 -0
- package/dist/metadata/decorators.d.ts.map +1 -0
- package/dist/metadata/decorators.js +38 -0
- package/dist/metadata/decorators.js.map +1 -0
- package/dist/metadata/generated.d.ts +18 -0
- package/dist/metadata/generated.d.ts.map +1 -0
- package/dist/metadata/generated.js +290 -0
- package/dist/metadata/generated.js.map +1 -0
- package/dist/metadata/index.d.ts +11 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +45 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/types.d.ts +22 -0
- package/dist/metadata/types.d.ts.map +1 -0
- package/dist/metadata/types.js +6 -0
- package/dist/metadata/types.js.map +1 -0
- package/dist/pause/index.d.ts +11 -0
- package/dist/pause/index.d.ts.map +1 -0
- package/dist/pause/index.js +15 -0
- package/dist/pause/index.js.map +1 -0
- package/dist/pause/types.d.ts +46 -0
- package/dist/pause/types.d.ts.map +1 -0
- package/dist/pause/types.js +57 -0
- package/dist/pause/types.js.map +1 -0
- package/dist/progress/index.d.ts +19 -0
- package/dist/progress/index.d.ts.map +1 -0
- package/dist/progress/index.js +61 -0
- package/dist/progress/index.js.map +1 -0
- package/dist/progress/types.d.ts +7 -0
- package/dist/progress/types.d.ts.map +1 -0
- package/dist/progress/types.js +2 -0
- package/dist/progress/types.js.map +1 -0
- package/dist/registry.d.ts +16 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +16 -0
- package/dist/registry.js.map +1 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +31 -0
- package/dist/utils.js.map +1 -0
- package/package.json +51 -0
- package/src/approval/handler.ts +26 -0
- package/src/approval/index.ts +95 -0
- package/src/approval/types.ts +23 -0
- package/src/cache/backends.ts +196 -0
- package/src/cache/index.ts +74 -0
- package/src/cache/types.ts +20 -0
- package/src/embedding/index.ts +153 -0
- package/src/embedding/types.ts +31 -0
- package/src/embedding/utils.ts +34 -0
- package/src/embedding/vector-store.ts +164 -0
- package/src/index.ts +35 -0
- package/src/llm/callback.ts +24 -0
- package/src/llm/index.ts +121 -0
- package/src/llm/replay.ts +141 -0
- package/src/llm/types.ts +29 -0
- package/src/log/index.ts +167 -0
- package/src/log/types.ts +21 -0
- package/src/metadata/decorators.ts +44 -0
- package/src/metadata/generated.ts +293 -0
- package/src/metadata/index.ts +61 -0
- package/src/metadata/types.ts +24 -0
- package/src/pause/index.ts +28 -0
- package/src/pause/types.ts +57 -0
- package/src/progress/index.ts +50 -0
- package/src/progress/types.ts +6 -0
- package/src/registry.ts +22 -0
- package/src/utils.ts +37 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata and Type Generation Utilities
|
|
3
|
+
*/
|
|
4
|
+
export type { RuntimeAPIParam, RuntimeAPIMethod, RuntimeAPIMetadata } from './types.js';
|
|
5
|
+
export { RuntimeAPI, RuntimeMethod } from './decorators.js';
|
|
6
|
+
import type { RuntimeAPIMetadata } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Generates TypeScript definitions from runtime API metadata
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateRuntimeTypes(apis: RuntimeAPIMetadata[]): string;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAgDvE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata and Type Generation Utilities
|
|
3
|
+
*/
|
|
4
|
+
export { RuntimeAPI, RuntimeMethod } from './decorators.js';
|
|
5
|
+
/**
|
|
6
|
+
* Generates TypeScript definitions from runtime API metadata
|
|
7
|
+
*/
|
|
8
|
+
export function generateRuntimeTypes(apis) {
|
|
9
|
+
let typescript = '// Runtime SDK\ndeclare const atp: {\n';
|
|
10
|
+
for (const api of apis) {
|
|
11
|
+
typescript += ` /**\n`;
|
|
12
|
+
for (const line of api.description.split('\n')) {
|
|
13
|
+
typescript += ` * ${line}\n`;
|
|
14
|
+
}
|
|
15
|
+
typescript += ` */\n`;
|
|
16
|
+
typescript += ` ${api.name}: {\n`;
|
|
17
|
+
for (const method of api.methods) {
|
|
18
|
+
typescript += ` /**\n`;
|
|
19
|
+
typescript += ` * ${method.description}\n`;
|
|
20
|
+
for (const param of method.params) {
|
|
21
|
+
if (param.description) {
|
|
22
|
+
typescript += ` * @param ${param.name} - ${param.description}\n`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (method.returns !== 'void') {
|
|
26
|
+
const returnDesc = method.returns.startsWith('Promise')
|
|
27
|
+
? 'Promise resolving to result'
|
|
28
|
+
: 'Result value';
|
|
29
|
+
typescript += ` * @returns ${returnDesc}\n`;
|
|
30
|
+
}
|
|
31
|
+
typescript += ` */\n`;
|
|
32
|
+
const paramStrings = method.params.map((p) => {
|
|
33
|
+
const optional = p.optional ? '?' : '';
|
|
34
|
+
const type = p.type.includes('\n') ? p.type.replace(/\n/g, '\n ') : p.type;
|
|
35
|
+
return `${p.name}${optional}: ${type}`;
|
|
36
|
+
});
|
|
37
|
+
typescript += ` ${method.name}(${paramStrings.join(', ')}): ${method.returns};\n`;
|
|
38
|
+
typescript += `\n`;
|
|
39
|
+
}
|
|
40
|
+
typescript += ` };\n\n`;
|
|
41
|
+
}
|
|
42
|
+
typescript += '};\n\n';
|
|
43
|
+
return typescript;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAI5D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAA0B;IAC9D,IAAI,UAAU,GAAG,wCAAwC,CAAC;IAE1D,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,UAAU,IAAI,SAAS,CAAC;QACxB,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,UAAU,IAAI,QAAQ,IAAI,IAAI,CAAC;QAChC,CAAC;QACD,UAAU,IAAI,SAAS,CAAC;QAExB,UAAU,IAAI,KAAK,GAAG,CAAC,IAAI,OAAO,CAAC;QAEnC,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAClC,UAAU,IAAI,WAAW,CAAC;YAC1B,UAAU,IAAI,UAAU,MAAM,CAAC,WAAW,IAAI,CAAC;YAE/C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBACnC,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;oBACvB,UAAU,IAAI,iBAAiB,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,WAAW,IAAI,CAAC;gBACtE,CAAC;YACF,CAAC;YAED,IAAI,MAAM,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;gBAC/B,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC;oBACtD,CAAC,CAAC,6BAA6B;oBAC/B,CAAC,CAAC,cAAc,CAAC;gBAClB,UAAU,IAAI,mBAAmB,UAAU,IAAI,CAAC;YACjD,CAAC;YAED,UAAU,IAAI,WAAW,CAAC;YAE1B,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC5C,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBAChF,OAAO,GAAG,CAAC,CAAC,IAAI,GAAG,QAAQ,KAAK,IAAI,EAAE,CAAC;YACxC,CAAC,CAAC,CAAC;YAEH,UAAU,IAAI,OAAO,MAAM,CAAC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,OAAO,KAAK,CAAC;YAErF,UAAU,IAAI,IAAI,CAAC;QACpB,CAAC;QAED,UAAU,IAAI,UAAU,CAAC;IAC1B,CAAC;IAED,UAAU,IAAI,QAAQ,CAAC;IAEvB,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common metadata interface for runtime APIs
|
|
3
|
+
* Each runtime module exports its metadata for the type generator
|
|
4
|
+
*/
|
|
5
|
+
export interface RuntimeAPIParam {
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
optional?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface RuntimeAPIMethod {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
params: RuntimeAPIParam[];
|
|
15
|
+
returns: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RuntimeAPIMetadata {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
methods: RuntimeAPIMethod[];
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/metadata/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/metadata/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PauseExecutionError, CallbackType } from './types.js';
|
|
2
|
+
export { PauseExecutionError, CallbackType, LLMOperation, EmbeddingOperation, ApprovalOperation, ToolOperation, } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Helper to create pause error
|
|
5
|
+
*/
|
|
6
|
+
export declare function pauseForCallback(type: CallbackType, operation: string, payload: Record<string, unknown>): never;
|
|
7
|
+
/**
|
|
8
|
+
* Check if error is a pause request
|
|
9
|
+
*/
|
|
10
|
+
export declare function isPauseError(error: unknown): error is PauseExecutionError;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pause/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/D,OAAO,EACN,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACb,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,KAAK,CAEP;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAEzE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PauseExecutionError } from './types.js';
|
|
2
|
+
export { PauseExecutionError, CallbackType, LLMOperation, EmbeddingOperation, ApprovalOperation, ToolOperation, } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Helper to create pause error
|
|
5
|
+
*/
|
|
6
|
+
export function pauseForCallback(type, operation, payload) {
|
|
7
|
+
throw new PauseExecutionError(type, operation, payload);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Check if error is a pause request
|
|
11
|
+
*/
|
|
12
|
+
export function isPauseError(error) {
|
|
13
|
+
return error instanceof PauseExecutionError;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pause/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAgB,MAAM,YAAY,CAAC;AAE/D,OAAO,EACN,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACb,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC/B,IAAkB,EAClB,SAAiB,EACjB,OAAgC;IAEhC,MAAM,IAAI,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,mBAAmB,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback types that can pause execution
|
|
3
|
+
*/
|
|
4
|
+
export declare enum CallbackType {
|
|
5
|
+
LLM = "llm",
|
|
6
|
+
APPROVAL = "approval",
|
|
7
|
+
EMBEDDING = "embedding",
|
|
8
|
+
TOOL = "tool"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* LLM callback operations
|
|
12
|
+
*/
|
|
13
|
+
export declare enum LLMOperation {
|
|
14
|
+
CALL = "call",
|
|
15
|
+
EXTRACT = "extract",
|
|
16
|
+
CLASSIFY = "classify"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Embedding callback operations
|
|
20
|
+
*/
|
|
21
|
+
export declare enum EmbeddingOperation {
|
|
22
|
+
EMBED = "embed",
|
|
23
|
+
SEARCH = "search"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Approval callback operations
|
|
27
|
+
*/
|
|
28
|
+
export declare enum ApprovalOperation {
|
|
29
|
+
REQUEST = "request"
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Tool callback operations
|
|
33
|
+
*/
|
|
34
|
+
export declare enum ToolOperation {
|
|
35
|
+
CALL = "call"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when execution needs to pause for client callback
|
|
39
|
+
*/
|
|
40
|
+
export declare class PauseExecutionError extends Error {
|
|
41
|
+
readonly type: CallbackType;
|
|
42
|
+
readonly operation: string;
|
|
43
|
+
readonly payload: Record<string, unknown>;
|
|
44
|
+
constructor(type: CallbackType, operation: string, payload: Record<string, unknown>);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pause/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,YAAY;IACvB,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,IAAI,SAAS;CACb;AAED;;GAEG;AACH,oBAAY,YAAY;IACvB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,QAAQ,aAAa;CACrB;AAED;;GAEG;AACH,oBAAY,kBAAkB;IAC7B,KAAK,UAAU;IACf,MAAM,WAAW;CACjB;AAED;;GAEG;AACH,oBAAY,iBAAiB;IAC5B,OAAO,YAAY;CACnB;AAED;;GAEG;AACH,oBAAY,aAAa;IACxB,IAAI,SAAS;CACb;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC7C,SAAgB,IAAI,EAAE,YAAY,CAAC;IACnC,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAErC,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOnF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback types that can pause execution
|
|
3
|
+
*/
|
|
4
|
+
export var CallbackType;
|
|
5
|
+
(function (CallbackType) {
|
|
6
|
+
CallbackType["LLM"] = "llm";
|
|
7
|
+
CallbackType["APPROVAL"] = "approval";
|
|
8
|
+
CallbackType["EMBEDDING"] = "embedding";
|
|
9
|
+
CallbackType["TOOL"] = "tool";
|
|
10
|
+
})(CallbackType || (CallbackType = {}));
|
|
11
|
+
/**
|
|
12
|
+
* LLM callback operations
|
|
13
|
+
*/
|
|
14
|
+
export var LLMOperation;
|
|
15
|
+
(function (LLMOperation) {
|
|
16
|
+
LLMOperation["CALL"] = "call";
|
|
17
|
+
LLMOperation["EXTRACT"] = "extract";
|
|
18
|
+
LLMOperation["CLASSIFY"] = "classify";
|
|
19
|
+
})(LLMOperation || (LLMOperation = {}));
|
|
20
|
+
/**
|
|
21
|
+
* Embedding callback operations
|
|
22
|
+
*/
|
|
23
|
+
export var EmbeddingOperation;
|
|
24
|
+
(function (EmbeddingOperation) {
|
|
25
|
+
EmbeddingOperation["EMBED"] = "embed";
|
|
26
|
+
EmbeddingOperation["SEARCH"] = "search";
|
|
27
|
+
})(EmbeddingOperation || (EmbeddingOperation = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Approval callback operations
|
|
30
|
+
*/
|
|
31
|
+
export var ApprovalOperation;
|
|
32
|
+
(function (ApprovalOperation) {
|
|
33
|
+
ApprovalOperation["REQUEST"] = "request";
|
|
34
|
+
})(ApprovalOperation || (ApprovalOperation = {}));
|
|
35
|
+
/**
|
|
36
|
+
* Tool callback operations
|
|
37
|
+
*/
|
|
38
|
+
export var ToolOperation;
|
|
39
|
+
(function (ToolOperation) {
|
|
40
|
+
ToolOperation["CALL"] = "call";
|
|
41
|
+
})(ToolOperation || (ToolOperation = {}));
|
|
42
|
+
/**
|
|
43
|
+
* Thrown when execution needs to pause for client callback
|
|
44
|
+
*/
|
|
45
|
+
export class PauseExecutionError extends Error {
|
|
46
|
+
type;
|
|
47
|
+
operation;
|
|
48
|
+
payload;
|
|
49
|
+
constructor(type, operation, payload) {
|
|
50
|
+
super(`Execution paused: waiting for ${type}.${operation}`);
|
|
51
|
+
this.name = 'PauseExecutionError';
|
|
52
|
+
this.type = type;
|
|
53
|
+
this.operation = operation;
|
|
54
|
+
this.payload = payload;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pause/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACvB,2BAAW,CAAA;IACX,qCAAqB,CAAA;IACrB,uCAAuB,CAAA;IACvB,6BAAa,CAAA;AACd,CAAC,EALW,YAAY,KAAZ,YAAY,QAKvB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACvB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;AACtB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC7B,qCAAe,CAAA;IACf,uCAAiB,CAAA;AAClB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,iBAEX;AAFD,WAAY,iBAAiB;IAC5B,wCAAmB,CAAA;AACpB,CAAC,EAFW,iBAAiB,KAAjB,iBAAiB,QAE5B;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,aAEX;AAFD,WAAY,aAAa;IACxB,8BAAa,CAAA;AACd,CAAC,EAFW,aAAa,KAAb,aAAa,QAExB;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC7B,IAAI,CAAe;IACnB,SAAS,CAAS;IAClB,OAAO,CAA0B;IAEjD,YAAY,IAAkB,EAAE,SAAiB,EAAE,OAAgC;QAClF,KAAK,CAAC,iCAAiC,IAAI,IAAI,SAAS,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ProgressCallback } from './types.js';
|
|
2
|
+
export type { ProgressCallback } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Set the progress callback handler
|
|
5
|
+
*/
|
|
6
|
+
export declare function setProgressCallback(callback: ProgressCallback | null): void;
|
|
7
|
+
/**
|
|
8
|
+
* Progress Runtime API
|
|
9
|
+
*
|
|
10
|
+
* Allows reporting execution progress to clients
|
|
11
|
+
*/
|
|
12
|
+
declare class ProgressAPI {
|
|
13
|
+
/**
|
|
14
|
+
* Report progress with message and completion fraction
|
|
15
|
+
*/
|
|
16
|
+
report(message: string, fraction: number): void;
|
|
17
|
+
}
|
|
18
|
+
export declare const progress: ProgressAPI;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/progress/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAOnD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAE3E;AAED;;;;GAIG;AACH,cACM,WAAW;IAChB;;OAEG;IAKH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;CAS/C;AAED,eAAO,MAAM,QAAQ,aAAoB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Progress API - Clean refactored version with decorators
|
|
12
|
+
*
|
|
13
|
+
* Benefits:
|
|
14
|
+
* - No duplication between implementation and metadata
|
|
15
|
+
* - Types auto-detected from TypeScript signatures
|
|
16
|
+
*/
|
|
17
|
+
import { RuntimeAPI, RuntimeMethod } from '../metadata/decorators.js';
|
|
18
|
+
/**
|
|
19
|
+
* Global progress callback (set by executor)
|
|
20
|
+
*/
|
|
21
|
+
let progressCallback = null;
|
|
22
|
+
/**
|
|
23
|
+
* Set the progress callback handler
|
|
24
|
+
*/
|
|
25
|
+
export function setProgressCallback(callback) {
|
|
26
|
+
progressCallback = callback;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Progress Runtime API
|
|
30
|
+
*
|
|
31
|
+
* Allows reporting execution progress to clients
|
|
32
|
+
*/
|
|
33
|
+
let ProgressAPI = class ProgressAPI {
|
|
34
|
+
/**
|
|
35
|
+
* Report progress with message and completion fraction
|
|
36
|
+
*/
|
|
37
|
+
report(message, fraction) {
|
|
38
|
+
if (progressCallback) {
|
|
39
|
+
try {
|
|
40
|
+
progressCallback(message, fraction);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('Progress callback error:', error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
__decorate([
|
|
49
|
+
RuntimeMethod('Report progress with message and completion fraction', {
|
|
50
|
+
message: { description: 'Progress message' },
|
|
51
|
+
fraction: { description: 'Completion fraction (0-1)' },
|
|
52
|
+
}),
|
|
53
|
+
__metadata("design:type", Function),
|
|
54
|
+
__metadata("design:paramtypes", [String, Number]),
|
|
55
|
+
__metadata("design:returntype", void 0)
|
|
56
|
+
], ProgressAPI.prototype, "report", null);
|
|
57
|
+
ProgressAPI = __decorate([
|
|
58
|
+
RuntimeAPI('progress', 'Progress API - Report execution progress to clients')
|
|
59
|
+
], ProgressAPI);
|
|
60
|
+
export const progress = new ProgressAPI();
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/progress/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAKtE;;GAEG;AACH,IAAI,gBAAgB,GAA4B,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAiC;IACpE,gBAAgB,GAAG,QAAQ,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AAEH,IAAM,WAAW,GAAjB,MAAM,WAAW;IAChB;;OAEG;IAKH,MAAM,CAAC,OAAe,EAAE,QAAgB;QACvC,IAAI,gBAAgB,EAAE,CAAC;YACtB,IAAI,CAAC;gBACJ,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAA;AATA;IAJC,aAAa,CAAC,sDAAsD,EAAE;QACtE,OAAO,EAAE,EAAE,WAAW,EAAE,kBAAkB,EAAE;QAC5C,QAAQ,EAAE,EAAE,WAAW,EAAE,2BAA2B,EAAE;KACtD,CAAC;;;;yCASD;AAhBI,WAAW;IADhB,UAAU,CAAC,UAAU,EAAE,qDAAqD,CAAC;GACxE,WAAW,CAiBhB;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/progress/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/progress/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime API Registry
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import type { RuntimeAPIMetadata } from './metadata/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Get all registered runtime APIs metadata
|
|
8
|
+
*
|
|
9
|
+
* This is generated at BUILD TIME by ts-morph, not at runtime
|
|
10
|
+
*/
|
|
11
|
+
export declare function getAllAPIs(): RuntimeAPIMetadata[];
|
|
12
|
+
/**
|
|
13
|
+
* Get metadata for a specific API by name
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAPI(name: string): RuntimeAPIMetadata | undefined;
|
|
16
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG9D;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,kBAAkB,EAAE,CAEjD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAEnE"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GENERATED_METADATA } from './metadata/generated.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get all registered runtime APIs metadata
|
|
4
|
+
*
|
|
5
|
+
* This is generated at BUILD TIME by ts-morph, not at runtime
|
|
6
|
+
*/
|
|
7
|
+
export function getAllAPIs() {
|
|
8
|
+
return GENERATED_METADATA;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get metadata for a specific API by name
|
|
12
|
+
*/
|
|
13
|
+
export function getAPI(name) {
|
|
14
|
+
return GENERATED_METADATA.find((api) => api.name === name);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACzB,OAAO,kBAAkB,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY;IAClC,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RetryOptions {
|
|
2
|
+
maxAttempts: number;
|
|
3
|
+
delayMs: number;
|
|
4
|
+
}
|
|
5
|
+
export declare const utils: {
|
|
6
|
+
sleep(ms: number): Promise<void>;
|
|
7
|
+
retry<T>(fn: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
8
|
+
parallel<T>(tasks: Array<() => Promise<T>>): Promise<T[]>;
|
|
9
|
+
sequence<T>(tasks: Array<() => Promise<T>>): Promise<T[]>;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,KAAK;cACD,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;UAI1B,CAAC,MAAM,MAAM,OAAO,CAAC,CAAC,CAAC,WAAW,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC;aAexD,CAAC,SAAS,KAAK,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;aAIhD,CAAC,SAAS,KAAK,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;CAO/D,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const utils = {
|
|
2
|
+
async sleep(ms) {
|
|
3
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
+
},
|
|
5
|
+
async retry(fn, options) {
|
|
6
|
+
let lastError;
|
|
7
|
+
for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {
|
|
8
|
+
try {
|
|
9
|
+
return await fn();
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
lastError = error;
|
|
13
|
+
if (attempt < options.maxAttempts) {
|
|
14
|
+
await this.sleep(options.delayMs);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
throw lastError;
|
|
19
|
+
},
|
|
20
|
+
async parallel(tasks) {
|
|
21
|
+
return Promise.all(tasks.map((task) => task()));
|
|
22
|
+
},
|
|
23
|
+
async sequence(tasks) {
|
|
24
|
+
const results = [];
|
|
25
|
+
for (const task of tasks) {
|
|
26
|
+
results.push(await task());
|
|
27
|
+
}
|
|
28
|
+
return results;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,KAAK,GAAG;IACpB,KAAK,CAAC,KAAK,CAAC,EAAU;QACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,KAAK,CAAI,EAAoB,EAAE,OAAqB;QACzD,IAAI,SAA4B,CAAC;QACjC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC;YACjE,IAAI,CAAC;gBACJ,OAAO,MAAM,EAAE,EAAE,CAAC;YACnB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,SAAS,GAAG,KAAc,CAAC;gBAC3B,IAAI,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;oBACnC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBACnC,CAAC;YACF,CAAC;QACF,CAAC;QACD,MAAM,SAAS,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAI,KAA8B;QAC/C,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAI,KAA8B;QAC/C,MAAM,OAAO,GAAQ,EAAE,CAAC;QACxB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;CACD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mondaydotcomorg/atp-runtime",
|
|
3
|
+
"version": "0.17.14",
|
|
4
|
+
"description": "Runtime SDK injected into sandbox for Agent Tool Protocol",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npm run generate:metadata && tsc -p tsconfig.json",
|
|
20
|
+
"generate:metadata": "tsx scripts/generate-metadata.ts",
|
|
21
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
22
|
+
"clean": "rm -rf dist *.tsbuildinfo src/metadata/generated.ts",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"lint": "tsc --noEmit"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"agent",
|
|
28
|
+
"protocol",
|
|
29
|
+
"runtime",
|
|
30
|
+
"sdk",
|
|
31
|
+
"ai",
|
|
32
|
+
"llm"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"ioredis": "^5.8.0",
|
|
37
|
+
"node-cache": "*",
|
|
38
|
+
"pino": "*",
|
|
39
|
+
"pino-pretty": "*",
|
|
40
|
+
"reflect-metadata": "^0.2.1",
|
|
41
|
+
"undici": "*"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^20.11.5",
|
|
45
|
+
"ts-json-schema-generator": "^2.4.0",
|
|
46
|
+
"ts-morph": "^21.0.1",
|
|
47
|
+
"tsx": "^4.7.0",
|
|
48
|
+
"typescript": "^5.3.3",
|
|
49
|
+
"vitest": "^1.2.1"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*/
|
|
3
|
+
import type { ApprovalRequest, ApprovalResponse } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Global approval handler that must be set by the execution context
|
|
7
|
+
*/
|
|
8
|
+
let approvalHandler: ((request: ApprovalRequest) => Promise<ApprovalResponse>) | null = null;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Initialize the approval system with a custom handler
|
|
12
|
+
*/
|
|
13
|
+
export function initializeApproval(
|
|
14
|
+
handler: (request: ApprovalRequest) => Promise<ApprovalResponse>
|
|
15
|
+
): void {
|
|
16
|
+
approvalHandler = handler;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get the current approval handler
|
|
21
|
+
*/
|
|
22
|
+
export function getApprovalHandler():
|
|
23
|
+
| ((request: ApprovalRequest) => Promise<ApprovalResponse>)
|
|
24
|
+
| null {
|
|
25
|
+
return approvalHandler;
|
|
26
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval API - Clean refactored version with decorators and extracted modules
|
|
3
|
+
*
|
|
4
|
+
* Benefits:
|
|
5
|
+
* - No duplication between implementation and metadata
|
|
6
|
+
* - Types auto-detected from TypeScript signatures
|
|
7
|
+
* - Clean separation of concerns (handler, API)
|
|
8
|
+
*/
|
|
9
|
+
import { RuntimeAPI, RuntimeMethod } from '../metadata/decorators.js';
|
|
10
|
+
import { getApprovalHandler } from './handler.js';
|
|
11
|
+
import { pauseForCallback, CallbackType, ApprovalOperation } from '../pause/index.js';
|
|
12
|
+
import type { ApprovalRequest, ApprovalResponse } from './types';
|
|
13
|
+
import { nextSequenceNumber, getCachedResult, shouldPauseForClient } from '../llm/replay.js';
|
|
14
|
+
|
|
15
|
+
export type { ApprovalRequest, ApprovalResponse, ApprovalSchema } from './types';
|
|
16
|
+
export { initializeApproval } from './handler.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Approval Runtime API
|
|
20
|
+
*
|
|
21
|
+
* Allows agents to request explicit human approval before proceeding with sensitive operations.
|
|
22
|
+
* This integrates with MCP's elicitation feature to request structured input from users.
|
|
23
|
+
*/
|
|
24
|
+
@RuntimeAPI('approval', 'Approval API - Request explicit human approval for sensitive operations')
|
|
25
|
+
class ApprovalAPI {
|
|
26
|
+
/**
|
|
27
|
+
* Request approval from a human
|
|
28
|
+
*/
|
|
29
|
+
@RuntimeMethod('Request approval from a human', {
|
|
30
|
+
message: {
|
|
31
|
+
description: 'The message to display to the user',
|
|
32
|
+
},
|
|
33
|
+
context: {
|
|
34
|
+
description: 'Optional context information about what needs approval',
|
|
35
|
+
optional: true,
|
|
36
|
+
type: 'Record<string, unknown>',
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
async request(message: string, context?: Record<string, unknown>): Promise<ApprovalResponse> {
|
|
40
|
+
const currentSequence = nextSequenceNumber();
|
|
41
|
+
|
|
42
|
+
const cachedResult = getCachedResult(currentSequence);
|
|
43
|
+
if (cachedResult !== undefined) {
|
|
44
|
+
return cachedResult as ApprovalResponse;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (shouldPauseForClient()) {
|
|
48
|
+
pauseForCallback(CallbackType.APPROVAL, ApprovalOperation.REQUEST, {
|
|
49
|
+
message,
|
|
50
|
+
context,
|
|
51
|
+
sequenceNumber: currentSequence,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const handler = getApprovalHandler();
|
|
56
|
+
|
|
57
|
+
if (!handler) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
'Approval handler not configured. Human approval is required but no handler is set.'
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const approvalRequest: ApprovalRequest = {
|
|
64
|
+
message,
|
|
65
|
+
context,
|
|
66
|
+
timeout: 300000,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
let timeoutId: NodeJS.Timeout | null = null;
|
|
70
|
+
const timeoutPromise = new Promise<ApprovalResponse>((_, reject) => {
|
|
71
|
+
timeoutId = setTimeout(
|
|
72
|
+
() => reject(new Error('Approval request timed out')),
|
|
73
|
+
approvalRequest.timeout!
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const response = await Promise.race([handler(approvalRequest), timeoutPromise]);
|
|
79
|
+
|
|
80
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
...response,
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
};
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Approval request failed: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const approval = new ApprovalAPI();
|