@bf-meishijian/aip 0.0.64 → 0.0.65

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.
Files changed (58) hide show
  1. package/dist/aip-submit-outcome/SKILL.md +41 -0
  2. package/dist/coding-run-error.js +1 -1
  3. package/dist/coding-run-manager.d.ts +1 -0
  4. package/dist/coding-run-manager.d.ts.map +1 -1
  5. package/dist/coding-run-manager.js +22 -3
  6. package/dist/coding-run-manager.js.map +1 -1
  7. package/dist/coding-subagents.d.ts +6 -1
  8. package/dist/coding-subagents.d.ts.map +1 -1
  9. package/dist/coding-subagents.js +306 -73
  10. package/dist/coding-subagents.js.map +1 -1
  11. package/dist/delivery-files.d.ts +3 -1
  12. package/dist/delivery-files.d.ts.map +1 -1
  13. package/dist/delivery-files.js +7 -4
  14. package/dist/delivery-files.js.map +1 -1
  15. package/dist/diagnostics.d.ts.map +1 -1
  16. package/dist/general-run-client.d.ts +2 -1
  17. package/dist/general-run-client.d.ts.map +1 -1
  18. package/dist/general-run-client.js +2 -2
  19. package/dist/general-run-client.js.map +1 -1
  20. package/dist/general-run-manager.d.ts.map +1 -1
  21. package/dist/general-run-manager.js +29 -4
  22. package/dist/general-run-manager.js.map +1 -1
  23. package/dist/general-run-supervisor.d.ts.map +1 -1
  24. package/dist/general-run-supervisor.js +17 -2
  25. package/dist/general-run-supervisor.js.map +1 -1
  26. package/dist/general-run-tools.d.ts +3 -0
  27. package/dist/general-run-tools.d.ts.map +1 -1
  28. package/dist/general-run-tools.js +175 -31
  29. package/dist/general-run-tools.js.map +1 -1
  30. package/dist/host-status.d.ts.map +1 -1
  31. package/dist/local-employee-runtime.d.ts +1 -0
  32. package/dist/local-employee-runtime.d.ts.map +1 -1
  33. package/dist/local-employee-runtime.js +106 -96
  34. package/dist/local-employee-runtime.js.map +1 -1
  35. package/dist/local-handoff-workspace.d.ts +27 -0
  36. package/dist/local-handoff-workspace.d.ts.map +1 -0
  37. package/dist/local-handoff-workspace.js +71 -0
  38. package/dist/local-handoff-workspace.js.map +1 -0
  39. package/dist/outcome-cli.d.ts +3 -0
  40. package/dist/outcome-cli.d.ts.map +1 -0
  41. package/dist/outcome-cli.js +91 -0
  42. package/dist/outcome-cli.js.map +1 -0
  43. package/dist/pi-model-retry.js +1 -1
  44. package/dist/pi-model-service.d.ts.map +1 -1
  45. package/dist/platform-client.d.ts.map +1 -1
  46. package/dist/skill-bundle-cache.js +1 -1
  47. package/dist/skill-directory-names.js +2 -58
  48. package/dist/skill-storage.d.ts +8 -1
  49. package/dist/skill-storage.d.ts.map +1 -1
  50. package/dist/skill-storage.js +37 -5
  51. package/dist/skill-storage.js.map +1 -1
  52. package/dist/tool-dispatch.js +1 -1
  53. package/dist/workflow-guidance.js +8 -6
  54. package/package.json +9 -9
  55. package/dist/generated/local-native-tools.js +0 -80
  56. package/dist/pi-path-utils.js +0 -141
  57. package/dist/provider-error.js +0 -147
  58. package/dist/skill-bundle.js +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bf-meishijian/aip",
3
- "version": "0.0.64",
3
+ "version": "0.0.65",
4
4
  "description": "AI Platform Local Coding Host",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,17 +12,17 @@
12
12
  ],
13
13
  "dependencies": {
14
14
  "@modelcontextprotocol/client": "2.0.0",
15
- "@earendil-works/pi-agent-core": "1.5.2",
16
- "@earendil-works/pi-ai": "1.5.2",
17
- "@earendil-works/pi-coding-agent": "1.5.2",
18
- "@earendil-works/pi-tui": "1.5.2",
15
+ "@earendil-works/pi-agent-core": "1.7.0",
16
+ "@earendil-works/pi-ai": "1.7.0",
17
+ "@earendil-works/pi-coding-agent": "1.7.0",
18
+ "@earendil-works/pi-tui": "1.7.0",
19
19
  "ajv": "8.17.1",
20
20
  "ajv-formats": "2.1.1",
21
21
  "cross-spawn": "7.0.6",
22
22
  "eventsource-parser": "3.1.1",
23
23
  "fast-xml-parser": "5.11.1",
24
24
  "npm": "11.9.0",
25
- "pi-subagents": "0.89.0",
25
+ "pi-subagents": "0.90.0",
26
26
  "proper-lockfile": "4.1.2",
27
27
  "typebox": "1.1.38"
28
28
  },
@@ -40,9 +40,9 @@
40
40
  },
41
41
  "license": "UNLICENSED",
42
42
  "optionalDependencies": {
43
- "@bf-meishijian/aip-runtime-darwin-arm64": "0.0.64",
44
- "@bf-meishijian/aip-runtime-win32-x64": "0.0.64",
45
- "@bf-meishijian/aip-runtime-linux-x64": "0.0.64"
43
+ "@bf-meishijian/aip-runtime-linux-x64": "0.0.65",
44
+ "@bf-meishijian/aip-runtime-win32-x64": "0.0.65",
45
+ "@bf-meishijian/aip-runtime-darwin-arm64": "0.0.65"
46
46
  },
47
47
  "publishConfig": {
48
48
  "tag": "latest"
@@ -1,80 +0,0 @@
1
- // ../../packages/api-contracts/src/generated/local-native-tools.ts
2
- var LOCAL_NATIVE_TOOL_SDK_VERSION = "1.5.2";
3
- var LOCAL_NATIVE_TOOL_DEFINITIONS = [
4
- {
5
- "name": "bash",
6
- "label": "bash",
7
- "description": "Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last 2000 lines or 50KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.",
8
- "parametersJson": '{"type":"object","required":["command"],"properties":{"command":{"type":"string","description":"Shell command to execute"},"timeout":{"type":"number","description":"Timeout in seconds (optional, no default timeout)"}}}',
9
- "promptSnippet": "Execute bash commands (ls, grep, find, etc.)",
10
- "promptGuidelines": [
11
- "You can inspect PI_* environment variables for current model and session details."
12
- ]
13
- },
14
- {
15
- "name": "powershell",
16
- "label": "powershell",
17
- "description": "Execute a PowerShell command in the current working directory. Returns stdout and stderr. Output is truncated to last 2000 lines or 50KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.",
18
- "parametersJson": '{"type":"object","required":["command"],"properties":{"command":{"type":"string","description":"Shell command to execute"},"timeout":{"type":"number","description":"Timeout in seconds (optional, no default timeout)"}}}',
19
- "promptSnippet": "Execute PowerShell commands",
20
- "promptGuidelines": [
21
- "You can inspect PI_* environment variables for current model and session details."
22
- ]
23
- },
24
- {
25
- "name": "read",
26
- "label": "read",
27
- "description": "Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.",
28
- "parametersJson": '{"type":"object","required":["path"],"properties":{"path":{"type":"string","description":"Path to the file to read (relative or absolute)"},"offset":{"type":"number","description":"Line number to start reading from (1-indexed)"},"limit":{"type":"number","description":"Maximum number of lines to read"}}}',
29
- "promptSnippet": "Read file contents",
30
- "promptGuidelines": [
31
- "Use read to examine files instead of cat or sed."
32
- ]
33
- },
34
- {
35
- "name": "write",
36
- "label": "write",
37
- "description": "Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
38
- "parametersJson": '{"type":"object","required":["path","content"],"properties":{"path":{"type":"string","description":"Path to the file to write (relative or absolute)"},"content":{"type":"string","description":"Content to write to the file"}}}',
39
- "promptSnippet": "Create or overwrite files",
40
- "promptGuidelines": [
41
- "Use write only for new files or complete rewrites."
42
- ]
43
- },
44
- {
45
- "name": "edit",
46
- "label": "edit",
47
- "description": "Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",
48
- "parametersJson": '{"type":"object","required":["path","edits"],"properties":{"path":{"type":"string","description":"Path to the file to edit (relative or absolute)"},"edits":{"type":"array","items":{"type":"object","required":["oldText","newText"],"properties":{"oldText":{"type":"string","description":"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call."},"newText":{"type":"string","description":"Replacement text for this targeted edit."}}},"description":"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead."}}}',
49
- "promptSnippet": "Make precise file edits with exact text replacement, including multiple disjoint edits in one call",
50
- "promptGuidelines": [
51
- "Use edit for targeted changes. Batch changes to one file in a single call.",
52
- "Each edits[].oldText must exactly and uniquely match the original file. Keep matches short and non-overlapping; merge nearby changes without including large unchanged regions."
53
- ]
54
- },
55
- {
56
- "name": "grep",
57
- "label": "grep",
58
- "description": "Search file contents for a pattern. Returns matching lines with file paths and line numbers. Respects .gitignore. Output is truncated to 100 matches or 50KB (whichever is hit first). Long lines are truncated to 500 chars.",
59
- "parametersJson": `{"type":"object","required":["pattern"],"properties":{"pattern":{"type":"string","description":"Search pattern (regex or literal string)"},"path":{"type":"string","description":"Directory or file to search (default: current directory)"},"glob":{"type":"string","description":"Filter files by glob pattern, relative to path, e.g. '*.ts', 'src/**/*.ts' or '**/*.spec.ts'. A pattern without '/' matches file names at any depth"},"ignoreCase":{"type":"boolean","description":"Case-insensitive search (default: false)"},"literal":{"type":"boolean","description":"Treat pattern as literal string instead of regex (default: false)"},"context":{"type":"number","description":"Number of lines to show before and after each match (default: 0)"},"limit":{"type":"number","description":"Maximum number of matches to return (default: 100)"}}}`,
60
- "promptSnippet": "Search file contents for patterns (respects .gitignore)"
61
- },
62
- {
63
- "name": "find",
64
- "label": "find",
65
- "description": "Search for files by glob pattern. Returns matching file paths relative to the search directory. Respects .gitignore. Output is truncated to 1000 results or 50KB (whichever is hit first).",
66
- "parametersJson": `{"type":"object","required":["pattern"],"properties":{"pattern":{"type":"string","description":"Glob pattern to match files, e.g. '*.ts', '**/*.json', or 'src/**/*.spec.ts'"},"path":{"type":"string","description":"Directory to search in (default: current directory)"},"limit":{"type":"number","description":"Maximum number of results (default: 1000)"}}}`,
67
- "promptSnippet": "Find files by glob pattern (respects .gitignore)"
68
- },
69
- {
70
- "name": "ls",
71
- "label": "ls",
72
- "description": "List directory contents. Returns entries sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Output is truncated to 500 entries or 50KB (whichever is hit first).",
73
- "parametersJson": '{"type":"object","properties":{"path":{"type":"string","description":"Directory to list (default: current directory)"},"limit":{"type":"number","description":"Maximum number of entries to return (default: 500)"}}}',
74
- "promptSnippet": "List directory contents"
75
- }
76
- ];
77
- export {
78
- LOCAL_NATIVE_TOOL_DEFINITIONS,
79
- LOCAL_NATIVE_TOOL_SDK_VERSION
80
- };
@@ -1,141 +0,0 @@
1
- // ../../node_modules/.pnpm/@earendil-works+pi-coding-agent@1.5.2_patch_hash=3b91a3a24f4f471f46fd65687cdd23cf84e270_6a7a78b9e707aead62d385d13d276b00/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js
2
- import { accessSync, constants } from "node:fs";
3
- import { access } from "node:fs/promises";
4
-
5
- // ../../node_modules/.pnpm/@earendil-works+pi-coding-agent@1.5.2_patch_hash=3b91a3a24f4f471f46fd65687cdd23cf84e270_6a7a78b9e707aead62d385d13d276b00/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.js
6
- import { homedir } from "node:os";
7
- import { isAbsolute, join, resolve as nodeResolvePath, posix, relative, sep, win32 } from "node:path";
8
- import { fileURLToPath } from "node:url";
9
-
10
- // ../../node_modules/.pnpm/@earendil-works+pi-coding-agent@1.5.2_patch_hash=3b91a3a24f4f471f46fd65687cdd23cf84e270_6a7a78b9e707aead62d385d13d276b00/node_modules/@earendil-works/pi-coding-agent/dist/utils/child-process.js
11
- import { channel } from "node:diagnostics_channel";
12
- import crossSpawn from "cross-spawn";
13
- var stdioRelease = channel("aip.pi.shell-stdio-release");
14
-
15
- // ../../node_modules/.pnpm/@earendil-works+pi-coding-agent@1.5.2_patch_hash=3b91a3a24f4f471f46fd65687cdd23cf84e270_6a7a78b9e707aead62d385d13d276b00/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.js
16
- var UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
17
- function normalizeWindowsShellPath(filePath) {
18
- if (!filePath.startsWith("/") || filePath.startsWith("//") || filePath.includes("\\"))
19
- return filePath;
20
- const match = filePath.match(/^\/(?:mnt\/|cygdrive\/)?([a-z])(?:\/(.*))?$/i);
21
- if (!match)
22
- return filePath;
23
- const suffix = match[2]?.replaceAll("/", "\\");
24
- return `${match[1].toUpperCase()}:\\${suffix ?? ""}`;
25
- }
26
- function normalizePath(input, options = {}) {
27
- let normalized = options.trim ? input.trim() : input;
28
- if (options.normalizeUnicodeSpaces) {
29
- normalized = normalized.replace(UNICODE_SPACES, " ");
30
- }
31
- if (options.stripAtPrefix && normalized.startsWith("@")) {
32
- normalized = normalized.slice(1);
33
- }
34
- if (process.platform === "win32") {
35
- normalized = normalizeWindowsShellPath(normalized);
36
- }
37
- if (options.expandTilde ?? true) {
38
- const home = options.homeDir ?? homedir();
39
- if (normalized === "~")
40
- return home;
41
- if (normalized.startsWith("~/") || process.platform === "win32" && normalized.startsWith("~\\")) {
42
- return join(home, normalized.slice(2));
43
- }
44
- }
45
- if (/^file:\/\//.test(normalized)) {
46
- return fileURLToPath(normalized);
47
- }
48
- return normalized;
49
- }
50
- function resolvePath(input, baseDir = process.cwd(), options = {}) {
51
- const normalized = normalizePath(input, options);
52
- const normalizedBaseDir = normalizePath(baseDir);
53
- return isAbsolute(normalized) ? nodeResolvePath(normalized) : nodeResolvePath(normalizedBaseDir, normalized);
54
- }
55
-
56
- // ../../node_modules/.pnpm/@earendil-works+pi-coding-agent@1.5.2_patch_hash=3b91a3a24f4f471f46fd65687cdd23cf84e270_6a7a78b9e707aead62d385d13d276b00/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js
57
- var NARROW_NO_BREAK_SPACE = "\u202F";
58
- function tryMacOSScreenshotPath(filePath) {
59
- return filePath.replace(/ (AM|PM)\./gi, `${NARROW_NO_BREAK_SPACE}$1.`);
60
- }
61
- function tryNFDVariant(filePath) {
62
- return filePath.normalize("NFD");
63
- }
64
- function tryCurlyQuoteVariant(filePath) {
65
- return filePath.replace(/'/g, "\u2019");
66
- }
67
- function fileExists(filePath) {
68
- try {
69
- accessSync(filePath, constants.F_OK);
70
- return true;
71
- } catch {
72
- return false;
73
- }
74
- }
75
- async function pathExists(filePath) {
76
- try {
77
- await access(filePath, constants.F_OK);
78
- return true;
79
- } catch {
80
- return false;
81
- }
82
- }
83
- function expandPath(filePath) {
84
- return normalizePath(filePath, { normalizeUnicodeSpaces: true, stripAtPrefix: true });
85
- }
86
- function resolveToCwd(filePath, cwd) {
87
- return resolvePath(filePath, cwd, { normalizeUnicodeSpaces: true, stripAtPrefix: true });
88
- }
89
- function resolveReadPath(filePath, cwd) {
90
- const resolved = resolveToCwd(filePath, cwd);
91
- if (fileExists(resolved)) {
92
- return resolved;
93
- }
94
- const amPmVariant = tryMacOSScreenshotPath(resolved);
95
- if (amPmVariant !== resolved && fileExists(amPmVariant)) {
96
- return amPmVariant;
97
- }
98
- const nfdVariant = tryNFDVariant(resolved);
99
- if (nfdVariant !== resolved && fileExists(nfdVariant)) {
100
- return nfdVariant;
101
- }
102
- const curlyVariant = tryCurlyQuoteVariant(resolved);
103
- if (curlyVariant !== resolved && fileExists(curlyVariant)) {
104
- return curlyVariant;
105
- }
106
- const nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);
107
- if (nfdCurlyVariant !== resolved && fileExists(nfdCurlyVariant)) {
108
- return nfdCurlyVariant;
109
- }
110
- return resolved;
111
- }
112
- async function resolveReadPathAsync(filePath, cwd) {
113
- const resolved = resolveToCwd(filePath, cwd);
114
- if (await pathExists(resolved)) {
115
- return resolved;
116
- }
117
- const amPmVariant = tryMacOSScreenshotPath(resolved);
118
- if (amPmVariant !== resolved && await pathExists(amPmVariant)) {
119
- return amPmVariant;
120
- }
121
- const nfdVariant = tryNFDVariant(resolved);
122
- if (nfdVariant !== resolved && await pathExists(nfdVariant)) {
123
- return nfdVariant;
124
- }
125
- const curlyVariant = tryCurlyQuoteVariant(resolved);
126
- if (curlyVariant !== resolved && await pathExists(curlyVariant)) {
127
- return curlyVariant;
128
- }
129
- const nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);
130
- if (nfdCurlyVariant !== resolved && await pathExists(nfdCurlyVariant)) {
131
- return nfdCurlyVariant;
132
- }
133
- return resolved;
134
- }
135
- export {
136
- expandPath,
137
- pathExists,
138
- resolveReadPath,
139
- resolveReadPathAsync,
140
- resolveToCwd
141
- };
@@ -1,147 +0,0 @@
1
- // ../../packages/api-contracts/src/provider-error.ts
2
- var safeErrorMessages = {
3
- rate_limit_exceeded: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u89E6\u53D1\u8BF7\u6C42\u9650\u6D41\u3002",
4
- too_many_requests: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u89E6\u53D1\u8BF7\u6C42\u9650\u6D41\u3002",
5
- insufficient_quota: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u53EF\u7528\u914D\u989D\u4E0D\u8DB3\u3002",
6
- context_length_exceeded: "\u8BF7\u6C42\u5185\u5BB9\u8D85\u8FC7\u4E0A\u6E38\u6A21\u578B\u7684\u4E0A\u4E0B\u6587\u957F\u5EA6\u9650\u5236\u3002",
7
- context_window_exceeded: "\u8BF7\u6C42\u5185\u5BB9\u8D85\u8FC7\u4E0A\u6E38\u6A21\u578B\u7684\u4E0A\u4E0B\u6587\u957F\u5EA6\u9650\u5236\u3002",
8
- max_tokens_exceeded: "\u8BF7\u6C42\u7684\u8F93\u51FA\u957F\u5EA6\u8D85\u8FC7\u4E0A\u6E38\u6A21\u578B\u9650\u5236\u3002",
9
- invalid_api_key: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62D2\u7EDD\u8BA4\u8BC1\u3002",
10
- authentication_error: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62D2\u7EDD\u8BA4\u8BC1\u3002",
11
- permission_denied: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62D2\u7EDD\u8BBF\u95EE\u3002",
12
- model_not_found: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u672A\u627E\u5230\u8BF7\u6C42\u7684\u6A21\u578B\u3002",
13
- content_filter: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62D2\u7EDD\u4E86\u8BF7\u6C42\u5185\u5BB9\u3002",
14
- invalid_request_error: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62D2\u7EDD\u4E86\u8BF7\u6C42\u53C2\u6570\u3002",
15
- unsupported_parameter: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u4E0D\u652F\u6301\u8BF7\u6C42\u4E2D\u7684\u53C2\u6570\u3002",
16
- invalid_parameter: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62D2\u7EDD\u4E86\u8BF7\u6C42\u53C2\u6570\u3002",
17
- server_error: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u5185\u90E8\u5F02\u5E38\u3002",
18
- overloaded_error: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u6682\u65F6\u8FC7\u8F7D\u3002",
19
- request_timeout: "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62A5\u544A\u8BF7\u6C42\u8D85\u65F6\u3002"
20
- };
21
- function safeProviderError(value) {
22
- return typeof value === "string" && Object.hasOwn(safeErrorMessages, value) ? { upstreamErrorCode: value, message: safeErrorMessages[value] } : void 0;
23
- }
24
- function providerStreamFailure(error, upstreamStatus, code) {
25
- const source = error && typeof error === "object" ? error : {};
26
- const upstreamCode = "code" in source ? source.code : void 0;
27
- const safeError = safeProviderError(upstreamCode);
28
- return {
29
- code,
30
- upstreamStatus,
31
- ...safeError ? { upstreamErrorCode: safeError.upstreamErrorCode } : {}
32
- };
33
- }
34
- var providerFailures = {
35
- PROVIDER_QUOTA_EXHAUSTED: ["QUOTA", "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u53EF\u7528\u914D\u989D\u4E0D\u8DB3\u3002", 402],
36
- PROVIDER_AUTHENTICATION_FAILED: ["AUTHENTICATION", "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62D2\u7EDD\u8BA4\u8BC1\u6216\u8BBF\u95EE\u3002", 403],
37
- MODEL_CONTEXT_WINDOW_EXCEEDED: ["CONTEXT_WINDOW", "\u8BF7\u6C42\u8D85\u8FC7\u6A21\u578B\u7684\u4E0A\u4E0B\u6587\u957F\u5EA6\u9650\u5236\u3002", 400],
38
- MODEL_OUTPUT_TRUNCATED: ["OUTPUT_LIMIT", "\u6A21\u578B\u8F93\u51FA\u8D85\u8FC7\u957F\u5EA6\u9650\u5236\uFF0C\u672C\u8F6E\u672A\u5B8C\u6210\u3002", 400],
39
- PROVIDER_REQUEST_REJECTED: ["REQUEST", "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u62D2\u7EDD\u4E86\u672C\u6B21\u8BF7\u6C42\u3002", 400],
40
- PROVIDER_RATE_LIMITED: ["OVERLOAD", "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u89E6\u53D1\u8BF7\u6C42\u9650\u6D41\u3002", 429],
41
- PROVIDER_UNAVAILABLE: ["OVERLOAD", "\u4E0A\u6E38\u6A21\u578B\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\u3002", 503],
42
- PROVIDER_STREAM_ERROR: ["STREAM", "\u4E0A\u6E38\u6A21\u578B\u54CD\u5E94\u6D41\u5F02\u5E38\u7ED3\u675F\u3002", 400],
43
- PROVIDER_STREAM_INTERRUPTED_AFTER_OUTPUT: ["STREAM", "\u6A21\u578B\u56DE\u590D\u4E2D\u9014\u65AD\u5F00\uFF0C\u672C\u8F6E\u672A\u5B8C\u6210\u3002", 400]
44
- };
45
- function providerFailure(code) {
46
- const [errorClass, safeMessage, httpStatus] = providerFailures[code];
47
- return { code, errorClass, safeMessage, httpStatus, retryable: errorClass === "OVERLOAD" };
48
- }
49
- function errorFields(value) {
50
- return value && typeof value === "object" ? value : {};
51
- }
52
- function classifyProviderError(value, status, options) {
53
- if (options?.visibleTextProduced)
54
- return providerFailure("PROVIDER_STREAM_INTERRUPTED_AFTER_OUTPUT");
55
- const envelope = errorFields(value);
56
- const error = errorFields(envelope.error ?? value);
57
- const codes = [error.code, error.type, envelope.code].map(
58
- (code) => typeof code === "string" || typeof code === "number" ? String(code).toLowerCase() : ""
59
- );
60
- const message = typeof error.message === "string" ? error.message : typeof envelope.error === "string" ? envelope.error : "";
61
- if (codes.some(
62
- (code) => /^(?:1308|provider_quota_exhausted|insufficient_(?:quota|balance)|quota_exceeded|payment_required|credit_balance_too_low|billing_.*|subscription_sharing_.*usage_limit_exceeded|gousagelimiterror|freeusagelimiterror)$/u.test(
63
- code
64
- )
65
- ) || /insufficient.quota|quota (?:exceeded|exhausted)|billing|out of budget|monthly usage limit reached|available balance|计费耗尽|余额不足|配额耗尽/iu.test(
66
- message
67
- ))
68
- return providerFailure("PROVIDER_QUOTA_EXHAUSTED");
69
- if (codes.some(
70
- (code) => /^(?:context_(?:length|window)_exceeded|model_context_window_exceeded)$/u.test(code)
71
- ) || /maximum context length|context (?:window|length) exceeded/iu.test(message))
72
- return providerFailure("MODEL_CONTEXT_WINDOW_EXCEEDED");
73
- if (codes.includes("max_tokens_exceeded") || codes.includes("model_output_truncated"))
74
- return providerFailure("MODEL_OUTPUT_TRUNCATED");
75
- if (status === 401 || status === 403 || codes.some(
76
- (code) => /^(?:invalid_api_key|authentication_error|permission_denied|provider_authentication_failed)$/u.test(
77
- code
78
- )
79
- ))
80
- return providerFailure("PROVIDER_AUTHENTICATION_FAILED");
81
- if (codes.some(
82
- (code) => /^(?:invalid_request_error|invalid_parameter|unsupported_parameter|content_filter|content_policy_violation|model_not_found|provider_request_rejected)$/u.test(
83
- code
84
- )
85
- ) || status !== void 0 && status >= 400 && status < 500 && status !== 408 && status !== 429)
86
- return providerFailure("PROVIDER_REQUEST_REJECTED");
87
- const knownCode = codes.find((code) => Object.hasOwn(providerFailures, code.toUpperCase()));
88
- if (knownCode) return providerFailure(knownCode.toUpperCase());
89
- if (status === 429 || codes.some(
90
- (code) => /^(?:rate_limit_exceeded|too_many_requests|provider_rate_limited)$/u.test(code)
91
- ) || /^Concurrency limit exceeded for account(?:,|$)/iu.test(message))
92
- return providerFailure("PROVIDER_RATE_LIMITED");
93
- if (status !== void 0 && [408, 500, 502, 503, 504].includes(status) || codes.some(
94
- (code) => /^(?:overloaded_error|overloaded|server_busy|server_error|request_timeout|service_unavailable|provider_unavailable)$/u.test(
95
- code
96
- )
97
- ) || /\boverloaded\b|\bserver_busy\b|\bcurrently experiencing high demand\b|\bmodel is at capacity\b/iu.test(
98
- message
99
- ))
100
- return providerFailure("PROVIDER_UNAVAILABLE");
101
- return providerFailure(options?.stream ? "PROVIDER_STREAM_ERROR" : "PROVIDER_REQUEST_REJECTED");
102
- }
103
- function piProviderError(failure) {
104
- const type = failure.code === "PROVIDER_QUOTA_EXHAUSTED" ? "insufficient_quota" : failure.retryable ? "overloaded_error" : failure.code;
105
- return {
106
- status: failure.httpStatus,
107
- body: {
108
- error: {
109
- code: failure.code,
110
- type,
111
- message: `${type}: ${failure.code}: ${failure.safeMessage}`
112
- }
113
- }
114
- };
115
- }
116
- async function readBoundedProviderError(response, maxBytes = 8192, idleMs = 2e3) {
117
- const reader = response.body?.getReader();
118
- if (!reader) return void 0;
119
- const decoder = new TextDecoder();
120
- let bytes = 0;
121
- let json = "";
122
- let timer;
123
- try {
124
- for (; ; ) {
125
- timer = setTimeout(() => void reader.cancel().catch(() => void 0), idleMs);
126
- const { done, value } = await reader.read();
127
- clearTimeout(timer);
128
- if (done) return JSON.parse(json + decoder.decode());
129
- bytes += value.byteLength;
130
- if (bytes > maxBytes) return void 0;
131
- json += decoder.decode(value, { stream: true });
132
- }
133
- } catch {
134
- return void 0;
135
- } finally {
136
- clearTimeout(timer);
137
- void reader.cancel().catch(() => void 0);
138
- reader.releaseLock();
139
- }
140
- }
141
- export {
142
- classifyProviderError,
143
- piProviderError,
144
- providerStreamFailure,
145
- readBoundedProviderError,
146
- safeProviderError
147
- };
@@ -1,9 +0,0 @@
1
- // ../../packages/api-contracts/src/skill-bundle.ts
2
- function canonicalSkillBundle(files) {
3
- return JSON.stringify(
4
- files.map(({ path, content }) => [path, content]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)
5
- );
6
- }
7
- export {
8
- canonicalSkillBundle
9
- };