@blazingagents/sdk 0.23.0 → 0.25.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/dist/chat-transport.d.ts +6 -0
- package/dist/chat-transport.js +15 -8
- package/dist/contracts/api.d.ts +0 -245
- package/dist/contracts/api.js +0 -121
- package/dist/contracts/entities/agent-tools.d.ts +0 -4
- package/dist/contracts/entities/agent-tools.js +0 -15
- package/dist/contracts/entities/agents.d.ts +2 -109
- package/dist/contracts/entities/agents.js +15 -16
- package/dist/contracts/entities/artifacts.d.ts +0 -30
- package/dist/contracts/entities/artifacts.js +1 -36
- package/dist/contracts/entities/attribution.d.ts +0 -2
- package/dist/contracts/entities/chat-connections.d.ts +0 -3
- package/dist/contracts/entities/chat-connections.js +0 -3
- package/dist/contracts/entities/chat.d.ts +1 -17
- package/dist/contracts/entities/chat.js +4 -13
- package/dist/contracts/entities/mcp-connections.d.ts +0 -168
- package/dist/contracts/entities/mcp-connections.js +1 -171
- package/dist/contracts/entities/memories.d.ts +0 -8
- package/dist/contracts/entities/memories.js +2 -15
- package/dist/contracts/entities/merchant.d.ts +0 -19
- package/dist/contracts/entities/merchant.js +1 -26
- package/dist/contracts/entities/prompts.d.ts +1 -14
- package/dist/contracts/entities/prompts.js +2 -3
- package/dist/contracts/entities/providers.d.ts +0 -28
- package/dist/contracts/entities/providers.js +1 -24
- package/dist/contracts/entities/sessions.d.ts +0 -9
- package/dist/contracts/entities/sessions.js +4 -21
- package/dist/contracts/entities/skills.d.ts +0 -52
- package/dist/contracts/entities/skills.js +2 -60
- package/dist/contracts/entities/tasks.d.ts +1 -168
- package/dist/contracts/entities/tasks.js +5 -14
- package/dist/contracts/entities/tenants.d.ts +0 -6
- package/dist/contracts/entities/usage.d.ts +0 -1
- package/dist/contracts/entities/workspaces.d.ts +0 -6
- package/dist/contracts/entities/workspaces.js +2 -14
- package/dist/contracts/ids.d.ts +1 -68
- package/dist/contracts/ids.js +2 -91
- package/dist/contracts/index.d.ts +3 -3
- package/dist/contracts/index.js +3 -3
- package/dist/contracts/limitations.d.ts +8 -81
- package/dist/contracts/limitations.js +8 -82
- package/dist/direct-chat-transport.d.ts +6 -0
- package/dist/direct-chat-transport.js +19 -2
- package/dist/generation.js +20 -4
- package/dist/types.d.ts +6 -0
- package/package.json +6 -6
|
@@ -2,33 +2,14 @@
|
|
|
2
2
|
* Effort-wide convention: every coded limit lives here as an UPPER_SNAKE_CASE
|
|
3
3
|
* constant. No scattered magic numbers.
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
6
|
-
* API keys — max 5 per tenant, name ≤ 80 (docs/adr/0004).
|
|
7
|
-
*/
|
|
8
|
-
export declare const MAX_API_KEYS_PER_TENANT = 5;
|
|
9
|
-
export declare const MAX_API_KEY_NAME_LENGTH = 80;
|
|
10
|
-
/** API key token shape — `ba_` + 40 base62 chars (~230 bits entropy). */
|
|
11
|
-
export declare const API_KEY_BODY_LENGTH = 40;
|
|
12
|
-
export declare const API_KEY_FRAGMENT_BODY_LENGTH = 2;
|
|
13
5
|
export declare const MAX_WORKSPACE_NAME_LENGTH = 80;
|
|
14
|
-
export declare const MAX_WORKSPACE_ARCHIVE_ENTRIES = 16384;
|
|
15
|
-
export declare const DEFAULT_WORKSPACES_LIST_LIMIT = 50;
|
|
16
|
-
export declare const MAX_WORKSPACES_LIST_LIMIT = 200;
|
|
17
6
|
/**
|
|
18
|
-
* Agent Skills —
|
|
19
|
-
*
|
|
20
|
-
* specification accepted in ADR-0028.
|
|
7
|
+
* Agent Skills — frontmatter follows the Agent Skills specification accepted
|
|
8
|
+
* in ADR-0028.
|
|
21
9
|
*/
|
|
22
|
-
export declare const MAX_SKILLS_PER_AGENT = 100;
|
|
23
|
-
export declare const MAX_SKILL_UPLOAD_BYTES: number;
|
|
24
|
-
export declare const MAX_SKILL_UNCOMPRESSED_BYTES: number;
|
|
25
|
-
export declare const MAX_SKILL_FILES = 100;
|
|
26
10
|
export declare const MAX_SKILL_NAME_LENGTH = 64;
|
|
27
11
|
export declare const MAX_SKILL_DESCRIPTION_LENGTH = 1024;
|
|
28
|
-
export declare const MAX_SKILL_COMPATIBILITY_LENGTH = 500;
|
|
29
12
|
export declare const MAX_SKILL_COPY_DESTINATIONS = 30;
|
|
30
|
-
export declare const DEFAULT_SKILLS_LIST_LIMIT = 50;
|
|
31
|
-
export declare const MAX_SKILLS_LIST_LIMIT = 100;
|
|
32
13
|
export declare const DEFAULT_PROMPTS_LIST_LIMIT = 50;
|
|
33
14
|
export declare const MAX_PROMPTS_LIST_LIMIT = 100;
|
|
34
15
|
export declare const MAX_PROMPT_TEMPLATE_BYTES: number;
|
|
@@ -38,16 +19,9 @@ export declare const MAX_PROMPT_NAME_LENGTH = 80;
|
|
|
38
19
|
export declare const MAX_TASK_NAME_LENGTH = 80;
|
|
39
20
|
export declare const MAX_TASK_PROMPT_LENGTH = 6000;
|
|
40
21
|
export declare const MIN_TASK_INTERVAL_MS = 60000;
|
|
41
|
-
/**
|
|
42
|
-
* Providers — max 20 per tenant, name ≤ 80.
|
|
43
|
-
*/
|
|
44
|
-
export declare const MAX_PROVIDERS_PER_TENANT = 20;
|
|
22
|
+
/** Providers — name ≤ 80. */
|
|
45
23
|
export declare const MAX_PROVIDER_NAME_LENGTH = 80;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* MCP Connections — max 50 per tenant, name ≤ 80, URL ≤ 2048.
|
|
49
|
-
*/
|
|
50
|
-
export declare const MAX_MCP_CONNECTIONS_PER_TENANT = 50;
|
|
24
|
+
/** MCP Connections — name ≤ 80, URL ≤ 2048. */
|
|
51
25
|
export declare const MAX_MCP_CONNECTIONS_PER_AGENT = 10;
|
|
52
26
|
export declare const MAX_MCP_CONNECTION_NAME_LENGTH = 80;
|
|
53
27
|
export declare const MAX_MCP_CONNECTION_URL_LENGTH = 2048;
|
|
@@ -60,54 +34,17 @@ export declare const MAX_MCP_SERVER_NAME_LENGTH = 200;
|
|
|
60
34
|
export declare const MAX_MCP_SERVER_VERSION_LENGTH = 100;
|
|
61
35
|
export declare const MAX_MCP_TOOL_NAME_LENGTH = 256;
|
|
62
36
|
export declare const MAX_MCP_TOOLS_PER_CONNECTION = 128;
|
|
63
|
-
export declare const MAX_MCP_TOOLS_PER_TURN = 256;
|
|
64
|
-
export declare const MAX_MCP_CONNECTION_SETUP_CONCURRENCY = 4;
|
|
65
|
-
export declare const MAX_MCP_TOOL_KEY_LENGTH = 63;
|
|
66
|
-
export declare const MAX_MCP_TOOL_DEFINITION_BYTES: number;
|
|
67
|
-
export declare const MAX_MCP_CONNECTION_TOOL_DEFINITIONS_BYTES: number;
|
|
68
|
-
export declare const MAX_MCP_TOOL_RESULT_BYTES: number;
|
|
69
37
|
export declare const MAX_MCP_ATTACHMENT_METADATA_KEYS = 32;
|
|
70
38
|
export declare const MAX_MCP_ATTACHMENT_METADATA_KEY_LENGTH = 64;
|
|
71
|
-
export declare const MAX_MCP_REQUEST_CONTEXT_BYTES: number;
|
|
72
39
|
/** Agents — name ≤ 80, instructions ≤ 3000. */
|
|
73
40
|
export declare const MAX_AGENT_NAME_LENGTH = 80;
|
|
74
41
|
export declare const DEFAULT_AGENTS_LIST_LIMIT = 50;
|
|
75
42
|
export declare const MAX_AGENTS_LIST_LIMIT = 100;
|
|
76
43
|
export declare const MAX_AGENT_INSTRUCTIONS_LENGTH = 3000;
|
|
77
|
-
/**
|
|
78
|
-
* Artifacts — 10 MiB per file, 10 publications per Tool call, and 100
|
|
79
|
-
* Artifacts per Session.
|
|
80
|
-
*/
|
|
44
|
+
/** Artifacts — 10 MiB per file. */
|
|
81
45
|
export declare const MAX_ARTIFACT_BYTES: number;
|
|
82
|
-
|
|
83
|
-
export declare const MAX_ARTIFACTS_PER_SESSION = 100;
|
|
84
|
-
/**
|
|
85
|
-
* Sandbox operations — 30-second native Cloudflare commands under a bounded
|
|
86
|
-
* private HTTP caller budget that includes cold Container startup. File
|
|
87
|
-
* transfers are 10 MiB decoded under a 15 MiB authenticated internal JSON
|
|
88
|
-
* request.
|
|
89
|
-
*/
|
|
90
|
-
export declare const CLOUDFLARE_SANDBOX_EXEC_MS = 30000;
|
|
91
|
-
export declare const MAX_SANDBOX_OPERATION_HTTP_MS = 160000;
|
|
92
|
-
export declare const MAX_SANDBOX_FILE_TRANSFER_BYTES: number;
|
|
93
|
-
export declare const MAX_SANDBOX_FILE_CHUNK_BYTES: number;
|
|
94
|
-
export declare const MAX_SANDBOX_REQUEST_BODY_BYTES: number;
|
|
95
|
-
/**
|
|
96
|
-
* Memories — one pool per Agent spanning all `userId` partitions, capped
|
|
97
|
-
* globally at 500 rows (LRU eviction on create), 10 KiB of text per memory
|
|
98
|
-
* (zod byte refine + DB `octet_length` check).
|
|
99
|
-
*/
|
|
100
|
-
export declare const MAX_MEMORIES_PER_AGENT = 500;
|
|
46
|
+
/** Memories — 10 KiB of text per memory. */
|
|
101
47
|
export declare const MAX_MEMORY_TEXT_BYTES: number;
|
|
102
|
-
export declare const DEFAULT_MEMORIES_LIST_LIMIT = 50;
|
|
103
|
-
export declare const MAX_MEMORIES_LIST_LIMIT = 100;
|
|
104
|
-
export declare const DEFAULT_MEMORY_TOOL_SEARCH_LIMIT = 10;
|
|
105
|
-
export declare const MAX_MEMORY_TOOL_SEARCH_LIMIT = 20;
|
|
106
|
-
/**
|
|
107
|
-
* Sessions — messages endpoint default limit 50, max 200.
|
|
108
|
-
*/
|
|
109
|
-
export declare const DEFAULT_SESSION_MESSAGES_LIMIT = 50;
|
|
110
|
-
export declare const MAX_SESSION_MESSAGES_LIMIT = 200;
|
|
111
48
|
/**
|
|
112
49
|
* Usage — range cap 31 days, default 30 days; top-N sessions default 50, max 200.
|
|
113
50
|
*/
|
|
@@ -124,19 +61,9 @@ export declare const MAX_QUOTA_RESET_DAY = 28;
|
|
|
124
61
|
*/
|
|
125
62
|
export declare const MAX_TENANT_NAME_LENGTH = 80;
|
|
126
63
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*/
|
|
130
|
-
export declare const TENANT_CREATION_BURST_LIMIT = 60;
|
|
131
|
-
export declare const TENANT_CREATION_BURST_WINDOW_MS = 60000;
|
|
132
|
-
export declare const TENANT_CREATION_SUSTAINED_LIMIT = 1000;
|
|
133
|
-
export declare const TENANT_CREATION_SUSTAINED_WINDOW_MS = 86400000;
|
|
134
|
-
/**
|
|
135
|
-
* Merchant monetization (ADR-0048) — bindings/usage-event list paging, guard
|
|
136
|
-
* rule bounds, and the delivery-health summary window.
|
|
64
|
+
* Merchant monetization (ADR-0048) — guard rule bounds and the delivery-health
|
|
65
|
+
* summary window.
|
|
137
66
|
*/
|
|
138
|
-
export declare const DEFAULT_MERCHANT_LIST_LIMIT = 50;
|
|
139
|
-
export declare const MAX_MERCHANT_LIST_LIMIT = 200;
|
|
140
67
|
export declare const MAX_MERCHANT_PRODUCT_IDS = 100;
|
|
141
68
|
export declare const DEFAULT_MERCHANT_USAGE_SUMMARY_DAYS = 14;
|
|
142
69
|
export declare const MAX_MERCHANT_USAGE_SUMMARY_DAYS = 90;
|
|
@@ -2,34 +2,14 @@
|
|
|
2
2
|
* Effort-wide convention: every coded limit lives here as an UPPER_SNAKE_CASE
|
|
3
3
|
* constant. No scattered magic numbers.
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
6
|
-
* API keys — max 5 per tenant, name ≤ 80 (docs/adr/0004).
|
|
7
|
-
*/
|
|
8
|
-
export const MAX_API_KEYS_PER_TENANT = 5;
|
|
9
|
-
export const MAX_API_KEY_NAME_LENGTH = 80;
|
|
10
|
-
/** API key token shape — `ba_` + 40 base62 chars (~230 bits entropy). */
|
|
11
|
-
export const API_KEY_BODY_LENGTH = 40;
|
|
12
|
-
// Display fragment — `ba_` + first 2 chars of the random body.
|
|
13
|
-
export const API_KEY_FRAGMENT_BODY_LENGTH = 2;
|
|
14
5
|
export const MAX_WORKSPACE_NAME_LENGTH = 80;
|
|
15
|
-
export const MAX_WORKSPACE_ARCHIVE_ENTRIES = 16_384;
|
|
16
|
-
export const DEFAULT_WORKSPACES_LIST_LIMIT = 50;
|
|
17
|
-
export const MAX_WORKSPACES_LIST_LIMIT = 200;
|
|
18
6
|
/**
|
|
19
|
-
* Agent Skills —
|
|
20
|
-
*
|
|
21
|
-
* specification accepted in ADR-0028.
|
|
7
|
+
* Agent Skills — frontmatter follows the Agent Skills specification accepted
|
|
8
|
+
* in ADR-0028.
|
|
22
9
|
*/
|
|
23
|
-
export const MAX_SKILLS_PER_AGENT = 100;
|
|
24
|
-
export const MAX_SKILL_UPLOAD_BYTES = 10 * 1024 * 1024;
|
|
25
|
-
export const MAX_SKILL_UNCOMPRESSED_BYTES = 10 * 1024 * 1024;
|
|
26
|
-
export const MAX_SKILL_FILES = 100;
|
|
27
10
|
export const MAX_SKILL_NAME_LENGTH = 64;
|
|
28
11
|
export const MAX_SKILL_DESCRIPTION_LENGTH = 1024;
|
|
29
|
-
export const MAX_SKILL_COMPATIBILITY_LENGTH = 500;
|
|
30
12
|
export const MAX_SKILL_COPY_DESTINATIONS = 30;
|
|
31
|
-
export const DEFAULT_SKILLS_LIST_LIMIT = 50;
|
|
32
|
-
export const MAX_SKILLS_LIST_LIMIT = 100;
|
|
33
13
|
export const DEFAULT_PROMPTS_LIST_LIMIT = 50;
|
|
34
14
|
export const MAX_PROMPTS_LIST_LIMIT = 100;
|
|
35
15
|
export const MAX_PROMPT_TEMPLATE_BYTES = 10 * 1024;
|
|
@@ -39,16 +19,9 @@ export const MAX_PROMPT_NAME_LENGTH = 80;
|
|
|
39
19
|
export const MAX_TASK_NAME_LENGTH = 80;
|
|
40
20
|
export const MAX_TASK_PROMPT_LENGTH = 6000;
|
|
41
21
|
export const MIN_TASK_INTERVAL_MS = 60_000;
|
|
42
|
-
/**
|
|
43
|
-
* Providers — max 20 per tenant, name ≤ 80.
|
|
44
|
-
*/
|
|
45
|
-
export const MAX_PROVIDERS_PER_TENANT = 20;
|
|
22
|
+
/** Providers — name ≤ 80. */
|
|
46
23
|
export const MAX_PROVIDER_NAME_LENGTH = 80;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* MCP Connections — max 50 per tenant, name ≤ 80, URL ≤ 2048.
|
|
50
|
-
*/
|
|
51
|
-
export const MAX_MCP_CONNECTIONS_PER_TENANT = 50;
|
|
24
|
+
/** MCP Connections — name ≤ 80, URL ≤ 2048. */
|
|
52
25
|
export const MAX_MCP_CONNECTIONS_PER_AGENT = 10;
|
|
53
26
|
export const MAX_MCP_CONNECTION_NAME_LENGTH = 80;
|
|
54
27
|
export const MAX_MCP_CONNECTION_URL_LENGTH = 2048;
|
|
@@ -61,54 +34,17 @@ export const MAX_MCP_SERVER_NAME_LENGTH = 200;
|
|
|
61
34
|
export const MAX_MCP_SERVER_VERSION_LENGTH = 100;
|
|
62
35
|
export const MAX_MCP_TOOL_NAME_LENGTH = 256;
|
|
63
36
|
export const MAX_MCP_TOOLS_PER_CONNECTION = 128;
|
|
64
|
-
export const MAX_MCP_TOOLS_PER_TURN = 256;
|
|
65
|
-
export const MAX_MCP_CONNECTION_SETUP_CONCURRENCY = 4;
|
|
66
|
-
export const MAX_MCP_TOOL_KEY_LENGTH = 63;
|
|
67
|
-
export const MAX_MCP_TOOL_DEFINITION_BYTES = 256 * 1024;
|
|
68
|
-
export const MAX_MCP_CONNECTION_TOOL_DEFINITIONS_BYTES = 1024 * 1024;
|
|
69
|
-
export const MAX_MCP_TOOL_RESULT_BYTES = 1024 * 1024;
|
|
70
37
|
export const MAX_MCP_ATTACHMENT_METADATA_KEYS = 32;
|
|
71
38
|
export const MAX_MCP_ATTACHMENT_METADATA_KEY_LENGTH = 64;
|
|
72
|
-
export const MAX_MCP_REQUEST_CONTEXT_BYTES = 16 * 1024;
|
|
73
39
|
/** Agents — name ≤ 80, instructions ≤ 3000. */
|
|
74
40
|
export const MAX_AGENT_NAME_LENGTH = 80;
|
|
75
41
|
export const DEFAULT_AGENTS_LIST_LIMIT = 50;
|
|
76
42
|
export const MAX_AGENTS_LIST_LIMIT = 100;
|
|
77
43
|
export const MAX_AGENT_INSTRUCTIONS_LENGTH = 3000;
|
|
78
|
-
/**
|
|
79
|
-
* Artifacts — 10 MiB per file, 10 publications per Tool call, and 100
|
|
80
|
-
* Artifacts per Session.
|
|
81
|
-
*/
|
|
44
|
+
/** Artifacts — 10 MiB per file. */
|
|
82
45
|
export const MAX_ARTIFACT_BYTES = 10 * 1024 * 1024;
|
|
83
|
-
|
|
84
|
-
export const MAX_ARTIFACTS_PER_SESSION = 100;
|
|
85
|
-
/**
|
|
86
|
-
* Sandbox operations — 30-second native Cloudflare commands under a bounded
|
|
87
|
-
* private HTTP caller budget that includes cold Container startup. File
|
|
88
|
-
* transfers are 10 MiB decoded under a 15 MiB authenticated internal JSON
|
|
89
|
-
* request.
|
|
90
|
-
*/
|
|
91
|
-
export const CLOUDFLARE_SANDBOX_EXEC_MS = 30_000;
|
|
92
|
-
export const MAX_SANDBOX_OPERATION_HTTP_MS = 160_000;
|
|
93
|
-
export const MAX_SANDBOX_FILE_TRANSFER_BYTES = 10 * 1024 * 1024;
|
|
94
|
-
export const MAX_SANDBOX_FILE_CHUNK_BYTES = 1024 * 1024;
|
|
95
|
-
export const MAX_SANDBOX_REQUEST_BODY_BYTES = 15 * 1024 * 1024;
|
|
96
|
-
/**
|
|
97
|
-
* Memories — one pool per Agent spanning all `userId` partitions, capped
|
|
98
|
-
* globally at 500 rows (LRU eviction on create), 10 KiB of text per memory
|
|
99
|
-
* (zod byte refine + DB `octet_length` check).
|
|
100
|
-
*/
|
|
101
|
-
export const MAX_MEMORIES_PER_AGENT = 500;
|
|
46
|
+
/** Memories — 10 KiB of text per memory. */
|
|
102
47
|
export const MAX_MEMORY_TEXT_BYTES = 10 * 1024;
|
|
103
|
-
export const DEFAULT_MEMORIES_LIST_LIMIT = 50;
|
|
104
|
-
export const MAX_MEMORIES_LIST_LIMIT = 100;
|
|
105
|
-
export const DEFAULT_MEMORY_TOOL_SEARCH_LIMIT = 10;
|
|
106
|
-
export const MAX_MEMORY_TOOL_SEARCH_LIMIT = 20;
|
|
107
|
-
/**
|
|
108
|
-
* Sessions — messages endpoint default limit 50, max 200.
|
|
109
|
-
*/
|
|
110
|
-
export const DEFAULT_SESSION_MESSAGES_LIMIT = 50;
|
|
111
|
-
export const MAX_SESSION_MESSAGES_LIMIT = 200;
|
|
112
48
|
/**
|
|
113
49
|
* Usage — range cap 31 days, default 30 days; top-N sessions default 50, max 200.
|
|
114
50
|
*/
|
|
@@ -126,19 +62,9 @@ export const MAX_QUOTA_RESET_DAY = 28;
|
|
|
126
62
|
*/
|
|
127
63
|
export const MAX_TENANT_NAME_LENGTH = 80;
|
|
128
64
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*/
|
|
132
|
-
export const TENANT_CREATION_BURST_LIMIT = 60;
|
|
133
|
-
export const TENANT_CREATION_BURST_WINDOW_MS = 60_000;
|
|
134
|
-
export const TENANT_CREATION_SUSTAINED_LIMIT = 1000;
|
|
135
|
-
export const TENANT_CREATION_SUSTAINED_WINDOW_MS = 86_400_000;
|
|
136
|
-
/**
|
|
137
|
-
* Merchant monetization (ADR-0048) — bindings/usage-event list paging, guard
|
|
138
|
-
* rule bounds, and the delivery-health summary window.
|
|
65
|
+
* Merchant monetization (ADR-0048) — guard rule bounds and the delivery-health
|
|
66
|
+
* summary window.
|
|
139
67
|
*/
|
|
140
|
-
export const DEFAULT_MERCHANT_LIST_LIMIT = 50;
|
|
141
|
-
export const MAX_MERCHANT_LIST_LIMIT = 200;
|
|
142
68
|
export const MAX_MERCHANT_PRODUCT_IDS = 100;
|
|
143
69
|
export const DEFAULT_MERCHANT_USAGE_SUMMARY_DAYS = 14;
|
|
144
70
|
export const MAX_MERCHANT_USAGE_SUMMARY_DAYS = 90;
|
|
@@ -17,6 +17,12 @@ export type BlazingAgentsDirectChatTransportOptions = {
|
|
|
17
17
|
* @param sessionId - Session to look up or record.
|
|
18
18
|
*/
|
|
19
19
|
onSessionId?: (sessionId: string) => Promise<void> | void;
|
|
20
|
+
/**
|
|
21
|
+
* Receives the running Turn ID before the response stream is consumed.
|
|
22
|
+
* Pass it to Stop.
|
|
23
|
+
* @param turnId - Turn the response runs.
|
|
24
|
+
*/
|
|
25
|
+
onTurnId?: (turnId: string) => Promise<void> | void;
|
|
20
26
|
sessionId?: string;
|
|
21
27
|
userId?: string;
|
|
22
28
|
} & ({
|
|
@@ -96,7 +96,8 @@ export class BlazingAgentsDirectChatTransport extends ChatStreamTransport {
|
|
|
96
96
|
return this.#processChatResult(result);
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
|
-
* Claims the chat stream and records the first Session ID
|
|
99
|
+
* Claims the chat stream and records the first Session ID and the Turn ID
|
|
100
|
+
* before decoding chunks.
|
|
100
101
|
*/
|
|
101
102
|
async #processChatResult(result) {
|
|
102
103
|
const stream = result.toStream();
|
|
@@ -106,6 +107,7 @@ export class BlazingAgentsDirectChatTransport extends ChatStreamTransport {
|
|
|
106
107
|
this.#sessionId = sessionId;
|
|
107
108
|
await this.#options.onSessionId?.(sessionId);
|
|
108
109
|
}
|
|
110
|
+
await this.#reportTurnId(result);
|
|
109
111
|
}
|
|
110
112
|
catch (error) {
|
|
111
113
|
await stream.cancel(error).catch(() => undefined);
|
|
@@ -141,6 +143,21 @@ export class BlazingAgentsDirectChatTransport extends ChatStreamTransport {
|
|
|
141
143
|
decisions,
|
|
142
144
|
functions: this.#options.functions ?? {},
|
|
143
145
|
});
|
|
144
|
-
|
|
146
|
+
const stream = continuation.toStream();
|
|
147
|
+
try {
|
|
148
|
+
await this.#reportTurnId(continuation);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
await stream.cancel(error).catch(() => undefined);
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
return this.processResponseStream(stream);
|
|
155
|
+
}
|
|
156
|
+
/** Reports the Turn ID when the response names one. */
|
|
157
|
+
async #reportTurnId(result) {
|
|
158
|
+
const turnId = await result.turnId.catch(() => undefined);
|
|
159
|
+
if (turnId !== undefined) {
|
|
160
|
+
await this.#options.onTurnId?.(turnId);
|
|
161
|
+
}
|
|
145
162
|
}
|
|
146
163
|
}
|
package/dist/generation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createTextStreamResponse, parsePartialJson } from "ai";
|
|
2
|
-
import { sessionIdSchema } from "./contracts/ids.js";
|
|
2
|
+
import { sessionIdSchema, turnIdSchema } from "./contracts/ids.js";
|
|
3
3
|
import { BlazingAgentsError } from "./errors.js";
|
|
4
4
|
import { dispatchChatFunctions, toChatFunctionDefinitions, } from "./functions.js";
|
|
5
5
|
import { requestStream } from "./http.js";
|
|
@@ -165,12 +165,24 @@ function buildChatResult(config, response, resumeSessionId, dispatch) {
|
|
|
165
165
|
sessionIdPromise.catch(() => {
|
|
166
166
|
/* no-op — prevents unhandled rejection if the caller never awaits */
|
|
167
167
|
});
|
|
168
|
+
const turnId = turnIdSchema.safeParse(response.headers.get("x-ba-turn-id"));
|
|
169
|
+
const turnIdPromise = turnId.success
|
|
170
|
+
? Promise.resolve(turnId.data)
|
|
171
|
+
: Promise.reject(new BlazingAgentsError({
|
|
172
|
+
code: "stream_error",
|
|
173
|
+
message: "The server did not return a valid turn id (X-BA-Turn-Id header).",
|
|
174
|
+
requestId: response.headers.get("x-request-id") ?? undefined,
|
|
175
|
+
}, { cause: turnId.error }));
|
|
176
|
+
turnIdPromise.catch(() => {
|
|
177
|
+
/* no-op — prevents unhandled rejection if the caller never awaits */
|
|
178
|
+
});
|
|
168
179
|
const { functions } = dispatch;
|
|
169
180
|
const streamResponse = functions && sessionId !== undefined
|
|
170
181
|
? withFilteredBody(response, (body) => dispatchChatFunctions(config, { ...dispatch, functions, sessionId }, body))
|
|
171
182
|
: response;
|
|
172
183
|
return {
|
|
173
184
|
sessionId: sessionIdPromise,
|
|
185
|
+
turnId: turnIdPromise,
|
|
174
186
|
...buildTerminalStreamResult(streamResponse, "chat"),
|
|
175
187
|
};
|
|
176
188
|
}
|
|
@@ -183,6 +195,7 @@ function buildChatResult(config, response, resumeSessionId, dispatch) {
|
|
|
183
195
|
export function buildTerminalStreamResult(response, resourceName, filter) {
|
|
184
196
|
const requestId = response.headers.get("x-request-id") ?? undefined;
|
|
185
197
|
const location = response.headers.get("location");
|
|
198
|
+
const turnId = response.headers.get("x-ba-turn-id");
|
|
186
199
|
let bodyClaimed = false;
|
|
187
200
|
/**
|
|
188
201
|
* Claims the response body once and normalizes stream failures.
|
|
@@ -207,7 +220,7 @@ export function buildTerminalStreamResult(response, resourceName, filter) {
|
|
|
207
220
|
toStream: claimBody,
|
|
208
221
|
/** Claims the response relay once. */
|
|
209
222
|
toResponse: () => {
|
|
210
|
-
const headers = replacementResponseHeaders(requestId, location);
|
|
223
|
+
const headers = replacementResponseHeaders(requestId, location, turnId);
|
|
211
224
|
headers.set("content-type", "text/event-stream");
|
|
212
225
|
headers.set("cache-control", "no-cache");
|
|
213
226
|
headers.set("connection", "keep-alive");
|
|
@@ -318,7 +331,7 @@ function responseBodyStream(response, requestId, resourceName) {
|
|
|
318
331
|
/**
|
|
319
332
|
* Copies request correlation and Session location into relay response headers.
|
|
320
333
|
*/
|
|
321
|
-
function replacementResponseHeaders(requestId, location) {
|
|
334
|
+
function replacementResponseHeaders(requestId, location, turnId) {
|
|
322
335
|
const headers = new Headers();
|
|
323
336
|
if (requestId !== undefined) {
|
|
324
337
|
headers.set("x-request-id", requestId);
|
|
@@ -326,6 +339,9 @@ function replacementResponseHeaders(requestId, location) {
|
|
|
326
339
|
if (location !== null) {
|
|
327
340
|
headers.set("location", location);
|
|
328
341
|
}
|
|
342
|
+
if (turnId !== null) {
|
|
343
|
+
headers.set("x-ba-turn-id", turnId);
|
|
344
|
+
}
|
|
329
345
|
return headers;
|
|
330
346
|
}
|
|
331
347
|
/**
|
|
@@ -501,7 +517,7 @@ function buildStatelessGenerationStreams(response, resourceName) {
|
|
|
501
517
|
}, { cause: new Error(message) });
|
|
502
518
|
}
|
|
503
519
|
responseBodyClaimed = true;
|
|
504
|
-
const headers = replacementResponseHeaders(requestId, location);
|
|
520
|
+
const headers = replacementResponseHeaders(requestId, location, null);
|
|
505
521
|
headers.set("content-type", "text/plain; charset=utf-8");
|
|
506
522
|
try {
|
|
507
523
|
return createTextStreamResponse({
|
package/dist/types.d.ts
CHANGED
|
@@ -200,6 +200,12 @@ export interface ChatResult {
|
|
|
200
200
|
* @throws BlazingAgentsError - If the response body has already been claimed.
|
|
201
201
|
*/
|
|
202
202
|
toStream: () => ReadableStream<Uint8Array>;
|
|
203
|
+
/**
|
|
204
|
+
* Resolves to the id of the Turn this response runs, read from the
|
|
205
|
+
* `X-BA-Turn-Id` header. Pass it to `sessions.stop()` to stop the Turn.
|
|
206
|
+
* Rejects with `stream_error` when the header is missing or malformed.
|
|
207
|
+
*/
|
|
208
|
+
turnId: Promise<string>;
|
|
203
209
|
}
|
|
204
210
|
export interface TerminalStreamResult {
|
|
205
211
|
requestId?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazingagents/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "TypeScript SDK for the Blazing Agents API",
|
|
5
5
|
"homepage": "https://docs.blazingagents.com",
|
|
6
6
|
"bugs": {
|
|
@@ -30,18 +30,17 @@
|
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
33
|
-
"check": "npm run typecheck && npm run test && npm run lint",
|
|
33
|
+
"check": "npm run typecheck && npm run test && npm run lint && npm run unused",
|
|
34
34
|
"fix": "ultracite fix",
|
|
35
35
|
"lint": "ultracite check",
|
|
36
36
|
"prepack": "npm run build",
|
|
37
37
|
"test": "vitest run --coverage",
|
|
38
38
|
"test:consumer": "node test-consumer.mjs",
|
|
39
|
-
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.tests.json"
|
|
39
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.tests.json",
|
|
40
|
+
"unused": "knip && knip --production --include exports,types,duplicates"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"croner": "10.0.1"
|
|
43
|
-
"nanoid": "6.0.1",
|
|
44
|
-
"yaml": "2.9.0"
|
|
43
|
+
"croner": "10.0.1"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@biomejs/biome": "^2.5.8",
|
|
@@ -49,6 +48,7 @@
|
|
|
49
48
|
"@types/node": "^26.4.0",
|
|
50
49
|
"@vitest/coverage-v8": "^4.1.10",
|
|
51
50
|
"ai": "^7.0.84",
|
|
51
|
+
"knip": "^6.41.0",
|
|
52
52
|
"typescript": "^7.0.2",
|
|
53
53
|
"ultracite": "^7.10.2",
|
|
54
54
|
"vitest": "^4.1.10",
|