@playcraft/common 0.0.55 → 0.0.57
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/agent/competitor-report.d.ts +165 -0
- package/dist/agent/competitor-report.d.ts.map +1 -0
- package/dist/agent/competitor-report.js +261 -0
- package/dist/agent/competitor-report.js.map +1 -0
- package/dist/agent/context-usage.d.ts +8 -1
- package/dist/agent/context-usage.d.ts.map +1 -1
- package/dist/agent/context-usage.js +6 -1
- package/dist/agent/context-usage.js.map +1 -1
- package/dist/agent/index.d.ts +6 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +6 -0
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/model-context-window.d.ts.map +1 -1
- package/dist/agent/model-context-window.js +40 -4
- package/dist/agent/model-context-window.js.map +1 -1
- package/dist/agent/openai-responses-api.d.ts +18 -0
- package/dist/agent/openai-responses-api.d.ts.map +1 -0
- package/dist/agent/openai-responses-api.js +28 -0
- package/dist/agent/openai-responses-api.js.map +1 -0
- package/dist/agent/reference-images.d.ts +66 -0
- package/dist/agent/reference-images.d.ts.map +1 -0
- package/dist/agent/reference-images.js +181 -0
- package/dist/agent/reference-images.js.map +1 -0
- package/dist/agent/runtime-failure.d.ts +31 -0
- package/dist/agent/runtime-failure.d.ts.map +1 -0
- package/dist/agent/runtime-failure.js +83 -0
- package/dist/agent/runtime-failure.js.map +1 -0
- package/dist/agent/session-title.d.ts +8 -0
- package/dist/agent/session-title.d.ts.map +1 -0
- package/dist/agent/session-title.js +16 -0
- package/dist/agent/session-title.js.map +1 -0
- package/dist/agent/turn.d.ts +8 -0
- package/dist/agent/turn.d.ts.map +1 -0
- package/dist/agent/turn.js +7 -0
- package/dist/agent/turn.js.map +1 -0
- package/dist/agent-jobs/identity.d.ts +8 -0
- package/dist/agent-jobs/identity.d.ts.map +1 -0
- package/dist/agent-jobs/identity.js +32 -0
- package/dist/agent-jobs/identity.js.map +1 -0
- package/dist/agent-jobs/index.d.ts +34 -0
- package/dist/agent-jobs/index.d.ts.map +1 -0
- package/dist/agent-jobs/index.js +39 -0
- package/dist/agent-jobs/index.js.map +1 -0
- package/dist/agent-jobs/legacy-http-gone.d.ts +13 -0
- package/dist/agent-jobs/legacy-http-gone.d.ts.map +1 -0
- package/dist/agent-jobs/legacy-http-gone.js +15 -0
- package/dist/agent-jobs/legacy-http-gone.js.map +1 -0
- package/dist/agent-jobs/legacy-run-task.d.ts +12 -0
- package/dist/agent-jobs/legacy-run-task.d.ts.map +1 -0
- package/dist/agent-jobs/legacy-run-task.js +14 -0
- package/dist/agent-jobs/legacy-run-task.js.map +1 -0
- package/dist/agent-jobs/portal-sandbox-team-mount.d.ts +8 -0
- package/dist/agent-jobs/portal-sandbox-team-mount.d.ts.map +1 -0
- package/dist/agent-jobs/portal-sandbox-team-mount.js +10 -0
- package/dist/agent-jobs/portal-sandbox-team-mount.js.map +1 -0
- package/dist/agent-jobs/runtime-metrics.d.ts +12 -0
- package/dist/agent-jobs/runtime-metrics.d.ts.map +1 -0
- package/dist/agent-jobs/runtime-metrics.js +19 -0
- package/dist/agent-jobs/runtime-metrics.js.map +1 -0
- package/dist/agent-jobs/runtime-timing.d.ts +21 -0
- package/dist/agent-jobs/runtime-timing.d.ts.map +1 -0
- package/dist/agent-jobs/runtime-timing.js +20 -0
- package/dist/agent-jobs/runtime-timing.js.map +1 -0
- package/dist/agent-jobs/runtime-v2.d.ts +8 -0
- package/dist/agent-jobs/runtime-v2.d.ts.map +1 -0
- package/dist/agent-jobs/runtime-v2.js +10 -0
- package/dist/agent-jobs/runtime-v2.js.map +1 -0
- package/dist/agent-messages/db-message-converter.d.ts +61 -0
- package/dist/agent-messages/db-message-converter.d.ts.map +1 -0
- package/dist/agent-messages/db-message-converter.js +478 -0
- package/dist/agent-messages/db-message-converter.js.map +1 -0
- package/dist/agent-messages/index.d.ts +4 -0
- package/dist/agent-messages/index.d.ts.map +1 -0
- package/dist/agent-messages/index.js +4 -0
- package/dist/agent-messages/index.js.map +1 -0
- package/dist/agent-messages/message-merge.d.ts +31 -0
- package/dist/agent-messages/message-merge.d.ts.map +1 -0
- package/dist/agent-messages/message-merge.js +221 -0
- package/dist/agent-messages/message-merge.js.map +1 -0
- package/dist/agent-messages/runtime-user-messages.d.ts +51 -0
- package/dist/agent-messages/runtime-user-messages.d.ts.map +1 -0
- package/dist/agent-messages/runtime-user-messages.js +296 -0
- package/dist/agent-messages/runtime-user-messages.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/prefab/index.d.ts +1 -0
- package/dist/prefab/index.d.ts.map +1 -1
- package/dist/prefab/index.js +1 -0
- package/dist/prefab/index.js.map +1 -1
- package/dist/prefab/schema-condition.d.ts +27 -0
- package/dist/prefab/schema-condition.d.ts.map +1 -0
- package/dist/prefab/schema-condition.js +107 -0
- package/dist/prefab/schema-condition.js.map +1 -0
- package/dist/prefab/schema-walker.d.ts +46 -4
- package/dist/prefab/schema-walker.d.ts.map +1 -1
- package/dist/prefab/schema-walker.js +155 -11
- package/dist/prefab/schema-walker.js.map +1 -1
- package/dist/prefab/types.d.ts +21 -2
- package/dist/prefab/types.d.ts.map +1 -1
- package/dist/recommend/atom-graph/basic-atom-graph.d.ts.map +1 -1
- package/dist/recommend/atom-graph/basic-atom-graph.js +80 -63
- package/dist/recommend/atom-graph/basic-atom-graph.js.map +1 -1
- package/dist/recommend/atom-graph/basic-atom-skill-graph.d.ts.map +1 -1
- package/dist/recommend/atom-graph/basic-atom-skill-graph.js +8 -0
- package/dist/recommend/atom-graph/basic-atom-skill-graph.js.map +1 -1
- package/dist/storage/cos.d.ts +4 -4
- package/dist/storage/cos.d.ts.map +1 -1
- package/dist/storage/cos.js +19 -1
- package/dist/storage/cos.js.map +1 -1
- package/dist/storage/interface.d.ts +5 -1
- package/dist/storage/interface.d.ts.map +1 -1
- package/package.json +32 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-responses-api.d.ts","sourceRoot":"","sources":["../../src/agent/openai-responses-api.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,yCAAyC,CAAC;AAE/E;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAI9E;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGlE;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGnE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const IEGG_LITELLM_DEFAULT_URL = 'https://litellm.ai.levelinfinite.com';
|
|
2
|
+
/**
|
|
3
|
+
* IEGG LiteLLM 官方入口是 `/v1/chat/completions`、`/v1/responses`。
|
|
4
|
+
* AI SDK 会把路径接在 baseURL 后面,所以 baseURL 必须自带 `/v1`,
|
|
5
|
+
* 否则会打到 `/chat/completions`、`/responses`。
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeIeggLiteLLMBaseUrl(apiBaseUrl) {
|
|
8
|
+
const raw = apiBaseUrl?.trim() || IEGG_LITELLM_DEFAULT_URL;
|
|
9
|
+
const trimmed = raw.replace(/\/+$/, '');
|
|
10
|
+
return trimmed.endsWith('/v1') ? trimmed : `${trimmed}/v1`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* GPT chat/reasoning 模型走 `/v1/responses`(`input`),Claude 等代理模型仍走
|
|
14
|
+
* `/v1/chat/completions`(`messages`)。
|
|
15
|
+
*/
|
|
16
|
+
export function shouldUseOpenAIResponsesApi(model) {
|
|
17
|
+
const normalized = (model.split('/').pop() ?? model).toLowerCase();
|
|
18
|
+
return /^gpt-\d/.test(normalized);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* OpenCode 仍走 openai-compatible Chat Completions。Azure gpt-6 + tools
|
|
22
|
+
* 在这条链路上必须显式 `reasoning_effort=none`。
|
|
23
|
+
*/
|
|
24
|
+
export function shouldForceChatReasoningNone(model) {
|
|
25
|
+
const normalized = (model.split('/').pop() ?? model).toLowerCase();
|
|
26
|
+
return /^gpt-6/.test(normalized);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=openai-responses-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-responses-api.js","sourceRoot":"","sources":["../../src/agent/openai-responses-api.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sCAAsC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,UAA0B;IACpE,MAAM,GAAG,GAAG,UAAU,EAAE,IAAI,EAAE,IAAI,wBAAwB,CAAC;IAC3D,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACxC,OAAO,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,KAAa;IACvD,MAAM,UAAU,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IACnE,OAAO,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAAa;IACxD,MAAM,UAAU,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IACnE,OAAO,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared sandbox protocol for user-attached reference images.
|
|
3
|
+
*
|
|
4
|
+
* Remix, Portal, OpenCode, CLI, and the remix editor must agree on:
|
|
5
|
+
* directory, allowed MIME (Multipurpose Internet Mail Extensions, 多用途互联网邮件扩展)
|
|
6
|
+
* types, prompt markers, and generate-image count. Do not copy these literals
|
|
7
|
+
* into feature packages.
|
|
8
|
+
*/
|
|
9
|
+
/** Project-relative directory. Absolute path = `{workDir}/{this}/{fileName}`. */
|
|
10
|
+
export declare const REFERENCE_IMAGE_RELATIVE_DIR = "tmp/opencode-images";
|
|
11
|
+
/** Prefix used by git exclude / change-gate ignore lists. */
|
|
12
|
+
export declare const REFERENCE_IMAGE_GIT_IGNORE_PATH = "tmp/opencode-images/";
|
|
13
|
+
/**
|
|
14
|
+
* Per-sandbox download cache, deliberately outside every project tree so no
|
|
15
|
+
* git exclude / change-gate entry is needed for it.
|
|
16
|
+
*
|
|
17
|
+
* File names are content-addressed, so a batch of variants downloads each
|
|
18
|
+
* attachment from object storage once and then copies inside the sandbox.
|
|
19
|
+
*/
|
|
20
|
+
export declare const REFERENCE_IMAGE_STAGING_ROOT = "/tmp/playcraft-reference-images";
|
|
21
|
+
/** Gemini / `playcraft-generate-image` hard cap. */
|
|
22
|
+
export declare const REFERENCE_IMAGE_MAX_COUNT = 8;
|
|
23
|
+
/** Remix editor + CLI prompt marker. */
|
|
24
|
+
export declare const REFERENCE_IMAGES_MARKER = "[Reference Images]";
|
|
25
|
+
/** Portal Manager / Executor sandbox-path notice. */
|
|
26
|
+
export declare const SANDBOX_REFERENCE_IMAGES_MARKER = "[Sandbox Reference Images]";
|
|
27
|
+
export declare const OPENCODE_REFERENCE_IMAGES_HEADING = "## User reference images";
|
|
28
|
+
/** Legacy remix UI copy; still stripped from stored prompts. */
|
|
29
|
+
export declare const LEGACY_ZH_REFERENCE_IMAGES_MARKER = "[\u53C2\u8003\u56FE\u7247]";
|
|
30
|
+
export declare const REFERENCE_IMAGE_MIME_TO_EXT: {
|
|
31
|
+
readonly 'image/jpeg': ".jpg";
|
|
32
|
+
readonly 'image/png': ".png";
|
|
33
|
+
readonly 'image/gif': ".gif";
|
|
34
|
+
readonly 'image/webp': ".webp";
|
|
35
|
+
};
|
|
36
|
+
export type ReferenceImageMimeType = keyof typeof REFERENCE_IMAGE_MIME_TO_EXT;
|
|
37
|
+
/** HTML `<input accept>` for Remix / Portal attachment pickers. */
|
|
38
|
+
export declare const REFERENCE_IMAGE_ACCEPT_ATTRIBUTE: string;
|
|
39
|
+
export declare function isReferenceImageMime(mimeType: string): boolean;
|
|
40
|
+
/** Canonical extension for sandbox / object-storage filenames (`.jpeg` → `.jpg`). */
|
|
41
|
+
export declare function referenceImageExtension(mimeType: string): string | undefined;
|
|
42
|
+
export declare function referenceImageMimeFromExtension(ext: string): string | undefined;
|
|
43
|
+
export declare function referenceImageExtensions(): readonly string[];
|
|
44
|
+
export declare function resolveReferenceImageDir(workDir: string): string;
|
|
45
|
+
export declare function buildReferenceImageRelativePath(fileName: string): string;
|
|
46
|
+
export declare function resolveReferenceImagePath(workDir: string, fileName: string): string;
|
|
47
|
+
export declare function resolveReferenceImageStagingDir(sessionId: string): string;
|
|
48
|
+
export declare function resolveReferenceImageStagingPath(sessionId: string, fileName: string): string;
|
|
49
|
+
export declare function isReferenceImageSandboxPath(value: string): boolean;
|
|
50
|
+
export declare function extractReferenceImagePathFromPromptLine(line: string): string | null;
|
|
51
|
+
export declare function splitReferenceImagePromptSection(text: string): {
|
|
52
|
+
userText: string;
|
|
53
|
+
section: string | null;
|
|
54
|
+
};
|
|
55
|
+
export declare function stripReferenceImagePromptSection(text: string): string;
|
|
56
|
+
export declare function extractReferenceImagePathsFromPrompt(text: string): string[];
|
|
57
|
+
export type ReferenceImageDigest = {
|
|
58
|
+
sha256: string;
|
|
59
|
+
mimeType: string;
|
|
60
|
+
};
|
|
61
|
+
/** Content-addressed sandbox file name: `{sha256[:16]}{ext}`. */
|
|
62
|
+
export declare function referenceImageFileName(attachment: ReferenceImageDigest): string;
|
|
63
|
+
export declare function matchReferenceImageAttachment<T extends ReferenceImageDigest>(sandboxPath: string, attachments: readonly T[]): T | undefined;
|
|
64
|
+
export declare function buildRemixReferenceImagesSection(sandboxPaths: string[]): string;
|
|
65
|
+
export declare function appendRemixReferenceImagesPrompt(userText: string, sandboxPaths: string[]): string;
|
|
66
|
+
//# sourceMappingURL=reference-images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-images.d.ts","sourceRoot":"","sources":["../../src/agent/reference-images.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,iFAAiF;AACjF,eAAO,MAAM,4BAA4B,wBAAwB,CAAC;AAElE,6DAA6D;AAC7D,eAAO,MAAM,+BAA+B,yBAAqC,CAAC;AAElF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,oCAAoC,CAAC;AAE9E,oDAAoD;AACpD,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,wCAAwC;AACxC,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAE5D,qDAAqD;AACrD,eAAO,MAAM,+BAA+B,+BAA+B,CAAC;AAE5E,eAAO,MAAM,iCAAiC,6BAA6B,CAAC;AAE5E,gEAAgE;AAChE,eAAO,MAAM,iCAAiC,+BAAW,CAAC;AAE1D,eAAO,MAAM,2BAA2B;;;;;CAK9B,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,2BAA2B,CAAC;AAE9E,mEAAmE;AACnE,eAAO,MAAM,gCAAgC,QAElC,CAAC;AAeZ,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAK9D;AAED,qFAAqF;AACrF,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG5E;AAED,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,MAAM,GAAG,MA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,MAAM,EAAE,GAAG,MAAM,CAqB/E;AAED,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EAAE,GACrB,MAAM,CAIR"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared sandbox protocol for user-attached reference images.
|
|
3
|
+
*
|
|
4
|
+
* Remix, Portal, OpenCode, CLI, and the remix editor must agree on:
|
|
5
|
+
* directory, allowed MIME (Multipurpose Internet Mail Extensions, 多用途互联网邮件扩展)
|
|
6
|
+
* types, prompt markers, and generate-image count. Do not copy these literals
|
|
7
|
+
* into feature packages.
|
|
8
|
+
*/
|
|
9
|
+
/** Project-relative directory. Absolute path = `{workDir}/{this}/{fileName}`. */
|
|
10
|
+
export const REFERENCE_IMAGE_RELATIVE_DIR = 'tmp/opencode-images';
|
|
11
|
+
/** Prefix used by git exclude / change-gate ignore lists. */
|
|
12
|
+
export const REFERENCE_IMAGE_GIT_IGNORE_PATH = `${REFERENCE_IMAGE_RELATIVE_DIR}/`;
|
|
13
|
+
/**
|
|
14
|
+
* Per-sandbox download cache, deliberately outside every project tree so no
|
|
15
|
+
* git exclude / change-gate entry is needed for it.
|
|
16
|
+
*
|
|
17
|
+
* File names are content-addressed, so a batch of variants downloads each
|
|
18
|
+
* attachment from object storage once and then copies inside the sandbox.
|
|
19
|
+
*/
|
|
20
|
+
export const REFERENCE_IMAGE_STAGING_ROOT = '/tmp/playcraft-reference-images';
|
|
21
|
+
/** Gemini / `playcraft-generate-image` hard cap. */
|
|
22
|
+
export const REFERENCE_IMAGE_MAX_COUNT = 8;
|
|
23
|
+
/** Remix editor + CLI prompt marker. */
|
|
24
|
+
export const REFERENCE_IMAGES_MARKER = '[Reference Images]';
|
|
25
|
+
/** Portal Manager / Executor sandbox-path notice. */
|
|
26
|
+
export const SANDBOX_REFERENCE_IMAGES_MARKER = '[Sandbox Reference Images]';
|
|
27
|
+
export const OPENCODE_REFERENCE_IMAGES_HEADING = '## User reference images';
|
|
28
|
+
/** Legacy remix UI copy; still stripped from stored prompts. */
|
|
29
|
+
export const LEGACY_ZH_REFERENCE_IMAGES_MARKER = '[参考图片]';
|
|
30
|
+
export const REFERENCE_IMAGE_MIME_TO_EXT = {
|
|
31
|
+
'image/jpeg': '.jpg',
|
|
32
|
+
'image/png': '.png',
|
|
33
|
+
'image/gif': '.gif',
|
|
34
|
+
'image/webp': '.webp',
|
|
35
|
+
};
|
|
36
|
+
/** HTML `<input accept>` for Remix / Portal attachment pickers. */
|
|
37
|
+
export const REFERENCE_IMAGE_ACCEPT_ATTRIBUTE = Object.keys(REFERENCE_IMAGE_MIME_TO_EXT).join(',');
|
|
38
|
+
const JPEG_MIME = 'image/jpeg';
|
|
39
|
+
function normalizeMime(mimeType) {
|
|
40
|
+
const mime = mimeType.trim().toLowerCase();
|
|
41
|
+
return mime === 'image/jpg' ? JPEG_MIME : mime;
|
|
42
|
+
}
|
|
43
|
+
function normalizeExtension(ext) {
|
|
44
|
+
const trimmed = ext.trim().toLowerCase();
|
|
45
|
+
if (!trimmed)
|
|
46
|
+
return '';
|
|
47
|
+
return trimmed.startsWith('.') ? trimmed : `.${trimmed}`;
|
|
48
|
+
}
|
|
49
|
+
export function isReferenceImageMime(mimeType) {
|
|
50
|
+
return Object.prototype.hasOwnProperty.call(REFERENCE_IMAGE_MIME_TO_EXT, normalizeMime(mimeType));
|
|
51
|
+
}
|
|
52
|
+
/** Canonical extension for sandbox / object-storage filenames (`.jpeg` → `.jpg`). */
|
|
53
|
+
export function referenceImageExtension(mimeType) {
|
|
54
|
+
const mime = normalizeMime(mimeType);
|
|
55
|
+
return REFERENCE_IMAGE_MIME_TO_EXT[mime];
|
|
56
|
+
}
|
|
57
|
+
export function referenceImageMimeFromExtension(ext) {
|
|
58
|
+
const normalized = normalizeExtension(ext);
|
|
59
|
+
if (normalized === '.jpeg')
|
|
60
|
+
return JPEG_MIME;
|
|
61
|
+
for (const [mime, mapped] of Object.entries(REFERENCE_IMAGE_MIME_TO_EXT)) {
|
|
62
|
+
if (mapped === normalized)
|
|
63
|
+
return mime;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
export function referenceImageExtensions() {
|
|
68
|
+
return ['.jpg', '.jpeg', '.png', '.gif', '.webp'];
|
|
69
|
+
}
|
|
70
|
+
function joinPosix(root, ...segments) {
|
|
71
|
+
const base = root.replace(/\/+$/, '');
|
|
72
|
+
const rest = segments.map((segment) => segment.replace(/^\/+|\/+$/g, '')).filter(Boolean);
|
|
73
|
+
return [base, ...rest].join('/');
|
|
74
|
+
}
|
|
75
|
+
export function resolveReferenceImageDir(workDir) {
|
|
76
|
+
return joinPosix(workDir, REFERENCE_IMAGE_RELATIVE_DIR);
|
|
77
|
+
}
|
|
78
|
+
export function buildReferenceImageRelativePath(fileName) {
|
|
79
|
+
return `${REFERENCE_IMAGE_RELATIVE_DIR}/${fileName.replace(/^\/+/, '')}`;
|
|
80
|
+
}
|
|
81
|
+
export function resolveReferenceImagePath(workDir, fileName) {
|
|
82
|
+
return joinPosix(workDir, buildReferenceImageRelativePath(fileName));
|
|
83
|
+
}
|
|
84
|
+
export function resolveReferenceImageStagingDir(sessionId) {
|
|
85
|
+
return joinPosix(REFERENCE_IMAGE_STAGING_ROOT, sessionId);
|
|
86
|
+
}
|
|
87
|
+
export function resolveReferenceImageStagingPath(sessionId, fileName) {
|
|
88
|
+
return joinPosix(resolveReferenceImageStagingDir(sessionId), fileName);
|
|
89
|
+
}
|
|
90
|
+
export function isReferenceImageSandboxPath(value) {
|
|
91
|
+
const path = value.trim().replace(/\\/g, '/').replace(/^[-*]\s+/, '');
|
|
92
|
+
const dir = REFERENCE_IMAGE_RELATIVE_DIR;
|
|
93
|
+
return (path === dir ||
|
|
94
|
+
path === `/${dir}` ||
|
|
95
|
+
path.startsWith(`${dir}/`) ||
|
|
96
|
+
path.startsWith(`/${dir}/`) ||
|
|
97
|
+
path.includes(`/${dir}/`));
|
|
98
|
+
}
|
|
99
|
+
export function extractReferenceImagePathFromPromptLine(line) {
|
|
100
|
+
const trimmed = line.trim().replace(/^[-*]\s+/, '');
|
|
101
|
+
return isReferenceImageSandboxPath(trimmed) ? trimmed : null;
|
|
102
|
+
}
|
|
103
|
+
const PROMPT_SECTION_MARKERS = [
|
|
104
|
+
REFERENCE_IMAGES_MARKER,
|
|
105
|
+
SANDBOX_REFERENCE_IMAGES_MARKER,
|
|
106
|
+
OPENCODE_REFERENCE_IMAGES_HEADING,
|
|
107
|
+
LEGACY_ZH_REFERENCE_IMAGES_MARKER,
|
|
108
|
+
];
|
|
109
|
+
export function splitReferenceImagePromptSection(text) {
|
|
110
|
+
let cut = -1;
|
|
111
|
+
for (const marker of PROMPT_SECTION_MARKERS) {
|
|
112
|
+
const needle = `\n\n${marker}`;
|
|
113
|
+
const idx = text.lastIndexOf(needle);
|
|
114
|
+
if (idx > cut)
|
|
115
|
+
cut = idx;
|
|
116
|
+
}
|
|
117
|
+
if (cut < 0)
|
|
118
|
+
return { userText: text, section: null };
|
|
119
|
+
return {
|
|
120
|
+
userText: text.slice(0, cut).trimEnd(),
|
|
121
|
+
section: text.slice(cut),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export function stripReferenceImagePromptSection(text) {
|
|
125
|
+
return splitReferenceImagePromptSection(text).userText;
|
|
126
|
+
}
|
|
127
|
+
export function extractReferenceImagePathsFromPrompt(text) {
|
|
128
|
+
const { section } = splitReferenceImagePromptSection(text);
|
|
129
|
+
if (!section)
|
|
130
|
+
return [];
|
|
131
|
+
const paths = [];
|
|
132
|
+
for (const line of section.split('\n')) {
|
|
133
|
+
const path = extractReferenceImagePathFromPromptLine(line);
|
|
134
|
+
if (path)
|
|
135
|
+
paths.push(path);
|
|
136
|
+
}
|
|
137
|
+
return paths;
|
|
138
|
+
}
|
|
139
|
+
/** Content-addressed sandbox file name: `{sha256[:16]}{ext}`. */
|
|
140
|
+
export function referenceImageFileName(attachment) {
|
|
141
|
+
const digest = attachment.sha256.replace(/[^a-fA-F0-9]/g, '').toLowerCase();
|
|
142
|
+
const stem = (digest || 'image').slice(0, 16);
|
|
143
|
+
const ext = referenceImageExtension(attachment.mimeType) ?? '.png';
|
|
144
|
+
return `${stem}${ext}`;
|
|
145
|
+
}
|
|
146
|
+
export function matchReferenceImageAttachment(sandboxPath, attachments) {
|
|
147
|
+
const fileName = sandboxPath.replace(/\\/g, '/').split('/').pop() ?? '';
|
|
148
|
+
if (!fileName)
|
|
149
|
+
return undefined;
|
|
150
|
+
return attachments.find((attachment) => referenceImageFileName(attachment) === fileName);
|
|
151
|
+
}
|
|
152
|
+
export function buildRemixReferenceImagesSection(sandboxPaths) {
|
|
153
|
+
if (sandboxPaths.length === 0)
|
|
154
|
+
return '';
|
|
155
|
+
const pathList = sandboxPaths.map((path) => `- ${path}`).join('\n');
|
|
156
|
+
return [
|
|
157
|
+
REFERENCE_IMAGES_MARKER,
|
|
158
|
+
`The user attached ${sandboxPaths.length} image(s) at these sandbox filesystem paths:`,
|
|
159
|
+
pathList,
|
|
160
|
+
'',
|
|
161
|
+
'These files have already been written to the sandbox filesystem.',
|
|
162
|
+
'',
|
|
163
|
+
'**IMPORTANT:** Do NOT read, open, or inspect any of these image files. Do NOT use tools like read_file, cat, or any other file reader on them. The paths themselves are all you need.',
|
|
164
|
+
'',
|
|
165
|
+
"Infer each image's purpose from the user's message (e.g. reference for style/composition, UI mockup, screenshot illustrating an issue, asset to import, etc.). For any image you judge to be a visual reference, pass its path directly to `playcraft-generate-image` — do NOT ask the user to confirm, and do NOT attempt to examine the image content first.",
|
|
166
|
+
'',
|
|
167
|
+
'When passing references to `playcraft-generate-image`:',
|
|
168
|
+
'- Put the first reference in `referenceImagePath`, remaining ones in `additionalReferenceImagePaths` as a comma-separated string.',
|
|
169
|
+
'- Preserve the original order.',
|
|
170
|
+
`- Up to ${REFERENCE_IMAGE_MAX_COUNT} references total; paths must not contain commas.`,
|
|
171
|
+
'- Save generated images under `src/theme/draft/assets/` unless the user explicitly asks for another project asset location.',
|
|
172
|
+
'- When reporting saved image paths back to the user, prefer `/project/<repo-relative-path>` such as `/project/src/theme/draft/assets/level-ref.png`, not the full `/projects/<projectId>/<branch>/...` path.',
|
|
173
|
+
].join('\n');
|
|
174
|
+
}
|
|
175
|
+
export function appendRemixReferenceImagesPrompt(userText, sandboxPaths) {
|
|
176
|
+
const section = buildRemixReferenceImagesSection(sandboxPaths);
|
|
177
|
+
if (!section)
|
|
178
|
+
return userText;
|
|
179
|
+
return userText ? `${userText}\n\n${section}` : section;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=reference-images.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-images.js","sourceRoot":"","sources":["../../src/agent/reference-images.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,iFAAiF;AACjF,MAAM,CAAC,MAAM,4BAA4B,GAAG,qBAAqB,CAAC;AAElE,6DAA6D;AAC7D,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,4BAA4B,GAAG,CAAC;AAElF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,iCAAiC,CAAC;AAE9E,oDAAoD;AACpD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,wCAAwC;AACxC,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAE5D,qDAAqD;AACrD,MAAM,CAAC,MAAM,+BAA+B,GAAG,4BAA4B,CAAC;AAE5E,MAAM,CAAC,MAAM,iCAAiC,GAAG,0BAA0B,CAAC;AAE5E,gEAAgE;AAChE,MAAM,CAAC,MAAM,iCAAiC,GAAG,QAAQ,CAAC;AAE1D,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,OAAO;CACb,CAAC;AAIX,mEAAmE;AACnE,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4
|
+
* A failed turn's `reason` is shown verbatim in the Portal Agent timeline, so a
|
|
5
|
+
* transport failure used to reach the user as vendor TLS (Transport Layer
|
|
6
|
+
* Security, 传输层安全) wording it cannot act on. Turning the recognized cases
|
|
7
|
+
* into stable codes lets the UI translate them and lets monitoring group them.
|
|
8
|
+
*
|
|
9
|
+
* Structural checks only — `@playcraft/common` must not depend on the AI SDK.
|
|
10
|
+
*/
|
|
11
|
+
/** The model gateway never answered: DNS, TCP, or the TLS handshake failed. */
|
|
12
|
+
export declare const RUNTIME_FAILURE_MODEL_GATEWAY_UNREACHABLE = "model_gateway_unreachable";
|
|
13
|
+
export declare const RUNTIME_FAILURE_CODES: readonly ["model_gateway_unreachable"];
|
|
14
|
+
export type RuntimeFailureCode = (typeof RUNTIME_FAILURE_CODES)[number];
|
|
15
|
+
export type RuntimeFailure = {
|
|
16
|
+
code: RuntimeFailureCode;
|
|
17
|
+
/** Gateway hostname when the transport reported one; aids ops triage. */
|
|
18
|
+
host?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function isRuntimeFailureCode(value: unknown): value is RuntimeFailureCode;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a code when the failure is one we can give advice about, else `null`
|
|
23
|
+
* so the caller keeps the original message rather than guessing.
|
|
24
|
+
*/
|
|
25
|
+
export declare function classifyRuntimeFailure(error: unknown): RuntimeFailure | null;
|
|
26
|
+
/**
|
|
27
|
+
* The string to persist as a turn's failure reason: a stable code when
|
|
28
|
+
* recognized, otherwise the original message unchanged.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runtimeFailureReason(error: unknown): string;
|
|
31
|
+
//# sourceMappingURL=runtime-failure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-failure.d.ts","sourceRoot":"","sources":["../../src/agent/runtime-failure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,yCAAyC,8BAA8B,CAAC;AAErF,eAAO,MAAM,qBAAqB,wCAAuD,CAAC;AAE1F,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,kBAAkB,CAAC;IACzB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAwCF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAEhF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAgB5E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAI3D"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classification of runtime turn failures that deserve an actionable message.
|
|
3
|
+
*
|
|
4
|
+
* A failed turn's `reason` is shown verbatim in the Portal Agent timeline, so a
|
|
5
|
+
* transport failure used to reach the user as vendor TLS (Transport Layer
|
|
6
|
+
* Security, 传输层安全) wording it cannot act on. Turning the recognized cases
|
|
7
|
+
* into stable codes lets the UI translate them and lets monitoring group them.
|
|
8
|
+
*
|
|
9
|
+
* Structural checks only — `@playcraft/common` must not depend on the AI SDK.
|
|
10
|
+
*/
|
|
11
|
+
/** The model gateway never answered: DNS, TCP, or the TLS handshake failed. */
|
|
12
|
+
export const RUNTIME_FAILURE_MODEL_GATEWAY_UNREACHABLE = 'model_gateway_unreachable';
|
|
13
|
+
export const RUNTIME_FAILURE_CODES = [RUNTIME_FAILURE_MODEL_GATEWAY_UNREACHABLE];
|
|
14
|
+
/**
|
|
15
|
+
* Node and undici codes raised before any HTTP response exists. `ECONNRESET`
|
|
16
|
+
* also covers a stream cut mid-response, which is why a classification always
|
|
17
|
+
* additionally requires the absence of a status code.
|
|
18
|
+
*/
|
|
19
|
+
const CONNECT_PHASE_CODES = new Set([
|
|
20
|
+
'EAI_AGAIN',
|
|
21
|
+
'ECONNABORTED',
|
|
22
|
+
'ECONNREFUSED',
|
|
23
|
+
'ECONNRESET',
|
|
24
|
+
'EHOSTUNREACH',
|
|
25
|
+
'ENETUNREACH',
|
|
26
|
+
'ENOTFOUND',
|
|
27
|
+
'EPIPE',
|
|
28
|
+
'ETIMEDOUT',
|
|
29
|
+
'UND_ERR_CONNECT_TIMEOUT',
|
|
30
|
+
'UND_ERR_SOCKET',
|
|
31
|
+
]);
|
|
32
|
+
function asRecord(value) {
|
|
33
|
+
return typeof value === 'object' && value !== null ? value : null;
|
|
34
|
+
}
|
|
35
|
+
function stringOrUndefined(value) {
|
|
36
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
37
|
+
}
|
|
38
|
+
/** `RetryError` hides the real failure in `lastError`; unwrap before matching. */
|
|
39
|
+
function unwrap(error) {
|
|
40
|
+
let current = asRecord(error);
|
|
41
|
+
for (let depth = 0; current && depth < 5; depth += 1) {
|
|
42
|
+
const last = asRecord(current.lastError);
|
|
43
|
+
if (!last)
|
|
44
|
+
return current;
|
|
45
|
+
current = last;
|
|
46
|
+
}
|
|
47
|
+
return current;
|
|
48
|
+
}
|
|
49
|
+
export function isRuntimeFailureCode(value) {
|
|
50
|
+
return RUNTIME_FAILURE_CODES.includes(value);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns a code when the failure is one we can give advice about, else `null`
|
|
54
|
+
* so the caller keeps the original message rather than guessing.
|
|
55
|
+
*/
|
|
56
|
+
export function classifyRuntimeFailure(error) {
|
|
57
|
+
const root = unwrap(error);
|
|
58
|
+
if (!root)
|
|
59
|
+
return null;
|
|
60
|
+
// An HTTP status means the gateway answered, so whatever went wrong is not
|
|
61
|
+
// reachability — a 429 whose socket later reset must not read as "check VPN".
|
|
62
|
+
if (root.statusCode !== undefined && root.statusCode !== null)
|
|
63
|
+
return null;
|
|
64
|
+
const cause = asRecord(root.cause);
|
|
65
|
+
const code = stringOrUndefined(cause?.code) ?? stringOrUndefined(root.code);
|
|
66
|
+
if (!code || !CONNECT_PHASE_CODES.has(code))
|
|
67
|
+
return null;
|
|
68
|
+
const host = stringOrUndefined(cause?.host) ?? stringOrUndefined(root.host);
|
|
69
|
+
return host
|
|
70
|
+
? { code: RUNTIME_FAILURE_MODEL_GATEWAY_UNREACHABLE, host }
|
|
71
|
+
: { code: RUNTIME_FAILURE_MODEL_GATEWAY_UNREACHABLE };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The string to persist as a turn's failure reason: a stable code when
|
|
75
|
+
* recognized, otherwise the original message unchanged.
|
|
76
|
+
*/
|
|
77
|
+
export function runtimeFailureReason(error) {
|
|
78
|
+
const classified = classifyRuntimeFailure(error);
|
|
79
|
+
if (classified)
|
|
80
|
+
return classified.code;
|
|
81
|
+
return error instanceof Error ? error.message : String(error);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=runtime-failure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-failure.js","sourceRoot":"","sources":["../../src/agent/runtime-failure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,yCAAyC,GAAG,2BAA2B,CAAC;AAErF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,yCAAyC,CAAU,CAAC;AAU1F;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,WAAW;IACX,cAAc;IACd,cAAc;IACd,YAAY;IACZ,cAAc;IACd,aAAa;IACb,WAAW;IACX,OAAO;IACP,WAAW;IACX,yBAAyB;IACzB,gBAAgB;CACjB,CAAC,CAAC;AAEH,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAE,KAAiC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC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,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzD,MAAM,IAAI,GAAG,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5E,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,IAAI,EAAE,yCAAyC,EAAE,IAAI,EAAE;QAC3D,CAAC,CAAC,EAAE,IAAI,EAAE,yCAAyC,EAAE,CAAC;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,MAAM,UAAU,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC;IACvC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical default for `agent_sessions.title` (DB column default + createSession).
|
|
3
|
+
* Keep in sync with `packages/backend/src/core/database/schema.ts` agentSessions.title default.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_AGENT_SESSION_TITLE = "New conversation";
|
|
6
|
+
/** True when title is still a placeholder and safe to auto-replace. */
|
|
7
|
+
export declare function isGenericAgentSessionTitle(title: string | null | undefined): boolean;
|
|
8
|
+
//# sourceMappingURL=session-title.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-title.d.ts","sourceRoot":"","sources":["../../src/agent/session-title.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,2BAA2B,qBAAqB,CAAC;AAE9D,uEAAuE;AACvE,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAMpF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical default for `agent_sessions.title` (DB column default + createSession).
|
|
3
|
+
* Keep in sync with `packages/backend/src/core/database/schema.ts` agentSessions.title default.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_AGENT_SESSION_TITLE = 'New conversation';
|
|
6
|
+
/** True when title is still a placeholder and safe to auto-replace. */
|
|
7
|
+
export function isGenericAgentSessionTitle(title) {
|
|
8
|
+
const normalized = title?.trim() ?? '';
|
|
9
|
+
if (!normalized)
|
|
10
|
+
return true;
|
|
11
|
+
if (normalized.toLowerCase() === DEFAULT_AGENT_SESSION_TITLE.toLowerCase())
|
|
12
|
+
return true;
|
|
13
|
+
// Rare leftovers from other providers / legacy clients
|
|
14
|
+
return /^new session\b/i.test(normalized) || /^untitled\b/i.test(normalized);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=session-title.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-title.js","sourceRoot":"","sources":["../../src/agent/session-title.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AAE9D,uEAAuE;AACvE,MAAM,UAAU,0BAA0B,CAAC,KAAgC;IACzE,MAAM,UAAU,GAAG,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACvC,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,IAAI,UAAU,CAAC,WAAW,EAAE,KAAK,2BAA2B,CAAC,WAAW,EAAE;QAAE,OAAO,IAAI,CAAC;IACxF,uDAAuD;IACvD,OAAO,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const AgentModeSchema: z.ZodEnum<{
|
|
3
|
+
zero_to_one: "zero_to_one";
|
|
4
|
+
creative_variant_batch: "creative_variant_batch";
|
|
5
|
+
competitor_replica: "competitor_replica";
|
|
6
|
+
}>;
|
|
7
|
+
export type AgentModeType = z.infer<typeof AgentModeSchema>;
|
|
8
|
+
//# sourceMappingURL=turn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn.d.ts","sourceRoot":"","sources":["../../src/agent/turn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe;;;;EAI1B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn.js","sourceRoot":"","sources":["../../src/agent/turn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC;IACpC,aAAa;IACb,wBAAwB;IACxB,oBAAoB;CACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentExecutionJobData, AgentManagerJobData } from './index.js';
|
|
2
|
+
export declare function buildManagerJobIdentity(sessionId: string, triggeredByMessageId: string): string;
|
|
3
|
+
export declare function buildExecutionJobIdentity(executionId: string): string;
|
|
4
|
+
/** Stable dispatch-table key for idempotent Execution retry requests. */
|
|
5
|
+
export declare function buildExecutionRetryRequestKey(previousExecutionId: string): string;
|
|
6
|
+
export declare function validateManagerJobIdentity(job: AgentManagerJobData): void;
|
|
7
|
+
export declare function validateExecutionJobIdentity(job: AgentExecutionJobData): void;
|
|
8
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/agent-jobs/identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAM7E,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAER;AAED,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,yEAAyE;AACzE,wBAAgB,6BAA6B,CAAC,mBAAmB,EAAE,MAAM,GAAG,MAAM,CAEjF;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,mBAAmB,GAAG,IAAI,CAazE;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,qBAAqB,GAAG,IAAI,CAK7E"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const MANAGER_KEY_PREFIX = 'agent-manager:';
|
|
2
|
+
const EXECUTION_KEY_PREFIX = 'agent-execution:';
|
|
3
|
+
const EXECUTION_RETRY_KEY_PREFIX = 'agent-execution-retry:';
|
|
4
|
+
export function buildManagerJobIdentity(sessionId, triggeredByMessageId) {
|
|
5
|
+
return `${MANAGER_KEY_PREFIX}${sessionId}:${triggeredByMessageId}`;
|
|
6
|
+
}
|
|
7
|
+
export function buildExecutionJobIdentity(executionId) {
|
|
8
|
+
return `${EXECUTION_KEY_PREFIX}${executionId}`;
|
|
9
|
+
}
|
|
10
|
+
/** Stable dispatch-table key for idempotent Execution retry requests. */
|
|
11
|
+
export function buildExecutionRetryRequestKey(previousExecutionId) {
|
|
12
|
+
return `${EXECUTION_RETRY_KEY_PREFIX}${previousExecutionId}`;
|
|
13
|
+
}
|
|
14
|
+
export function validateManagerJobIdentity(job) {
|
|
15
|
+
const suffix = job.triggeredByMessageId;
|
|
16
|
+
if (suffix == null) {
|
|
17
|
+
throw new Error('Manager job requires triggeredByMessageId for idempotency identity');
|
|
18
|
+
}
|
|
19
|
+
const expected = buildManagerJobIdentity(job.sessionId, suffix);
|
|
20
|
+
// Exact match for initial turns; `:hitl:<toolCallId>` suffix for HITL resume dispatches.
|
|
21
|
+
if (job.idempotencyKey !== expected &&
|
|
22
|
+
!job.idempotencyKey.startsWith(`${expected}:hitl:`)) {
|
|
23
|
+
throw new Error('Manager idempotencyKey does not match job identity');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function validateExecutionJobIdentity(job) {
|
|
27
|
+
const expected = buildExecutionJobIdentity(job.executionId);
|
|
28
|
+
if (!job.idempotencyKey.startsWith(expected)) {
|
|
29
|
+
throw new Error('Execution idempotencyKey does not match job identity');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/agent-jobs/identity.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAC5C,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAChD,MAAM,0BAA0B,GAAG,wBAAwB,CAAC;AAE5D,MAAM,UAAU,uBAAuB,CACrC,SAAiB,EACjB,oBAA4B;IAE5B,OAAO,GAAG,kBAAkB,GAAG,SAAS,IAAI,oBAAoB,EAAE,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,WAAmB;IAC3D,OAAO,GAAG,oBAAoB,GAAG,WAAW,EAAE,CAAC;AACjD,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,6BAA6B,CAAC,mBAA2B;IACvE,OAAO,GAAG,0BAA0B,GAAG,mBAAmB,EAAE,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,GAAwB;IACjE,MAAM,MAAM,GAAG,GAAG,CAAC,oBAAoB,CAAC;IACxC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;IACD,MAAM,QAAQ,GAAG,uBAAuB,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAChE,yFAAyF;IACzF,IACE,GAAG,CAAC,cAAc,KAAK,QAAQ;QAC/B,CAAC,GAAG,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,QAAQ,QAAQ,CAAC,EACnD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,GAA0B;IACrE,MAAM,QAAQ,GAAG,yBAAyB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC5D,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const AGENT_JOB_SCHEMA_VERSION: 1;
|
|
3
|
+
export declare const AgentManagerJobDataSchema: z.ZodObject<{
|
|
4
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
5
|
+
idempotencyKey: z.ZodString;
|
|
6
|
+
workspaceId: z.ZodString;
|
|
7
|
+
sessionId: z.ZodString;
|
|
8
|
+
taskRunId: z.ZodUUID;
|
|
9
|
+
triggeredByMessageId: z.ZodOptional<z.ZodString>;
|
|
10
|
+
clientRequestId: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export type AgentManagerJobData = z.infer<typeof AgentManagerJobDataSchema>;
|
|
13
|
+
export declare const AgentExecutionJobDataSchema: z.ZodObject<{
|
|
14
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
15
|
+
idempotencyKey: z.ZodString;
|
|
16
|
+
workspaceId: z.ZodString;
|
|
17
|
+
sessionId: z.ZodString;
|
|
18
|
+
taskRunId: z.ZodUUID;
|
|
19
|
+
issueId: z.ZodUUID;
|
|
20
|
+
executionId: z.ZodUUID;
|
|
21
|
+
}, z.core.$strict>;
|
|
22
|
+
export type AgentExecutionJobData = z.infer<typeof AgentExecutionJobDataSchema>;
|
|
23
|
+
export { buildExecutionJobIdentity, buildExecutionRetryRequestKey, buildManagerJobIdentity, validateExecutionJobIdentity, validateManagerJobIdentity, } from './identity.js';
|
|
24
|
+
/** @deprecated Prefer buildExecutionRetryRequestKey from identity.js */
|
|
25
|
+
export declare function buildExecutionRetryKeys(executionId: string): {
|
|
26
|
+
dispatchKey: string;
|
|
27
|
+
};
|
|
28
|
+
export { isPortalAgentLegacyRunTaskEnabled } from './legacy-run-task.js';
|
|
29
|
+
export { isPortalAgentLegacyHttpGoneEnabled } from './legacy-http-gone.js';
|
|
30
|
+
export { isPortalAgentRuntimeV2Enabled } from './runtime-v2.js';
|
|
31
|
+
export { isPortalAgentSandboxTeamMountEnabled } from './portal-sandbox-team-mount.js';
|
|
32
|
+
export { PORTAL_AGENT_DB_LEASE_MS, PORTAL_AGENT_HEARTBEAT_INTERVAL_MS, PORTAL_AGENT_REDIS_SLOT_TTL_MS, PORTAL_AGENT_SESSION_MUTEX_TTL_MS, PORTAL_AGENT_BULLMQ_LOCK_DURATION_MS, PORTAL_AGENT_BULLMQ_STALLED_INTERVAL_MS, PORTAL_AGENT_RUNTIME_TIMING, type PortalAgentRuntimeTiming, } from './runtime-timing.js';
|
|
33
|
+
export { noopAgentRuntimeMetrics, createLoggingAgentRuntimeMetrics, type AgentRuntimeMetrics, type AgentRuntimeMetricsLogger, } from './runtime-metrics.js';
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent-jobs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,wBAAwB,EAAG,CAAU,CAAC;AAenD,eAAO,MAAM,yBAAyB;;;;;;;;kBAK3B,CAAC;AAEZ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E,eAAO,MAAM,2BAA2B;;;;;;;;kBAK7B,CAAC;AAEZ,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,EACvB,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,wEAAwE;AACxE,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG;IAC5D,WAAW,EAAE,MAAM,CAAC;CACrB,CAIA;AAED,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,kCAAkC,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,6BAA6B,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,oCAAoC,EAAE,MAAM,gCAAgC,CAAC;AAEtF,OAAO,EACL,wBAAwB,EACxB,kCAAkC,EAClC,8BAA8B,EAC9B,iCAAiC,EACjC,oCAAoC,EACpC,uCAAuC,EACvC,2BAA2B,EAC3B,KAAK,wBAAwB,GAC9B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,GAC/B,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const AGENT_JOB_SCHEMA_VERSION = 1;
|
|
3
|
+
const durableReferenceSchema = z.string().trim().min(1).max(256);
|
|
4
|
+
const uuidReferenceSchema = z.uuid();
|
|
5
|
+
const agentJobBaseSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
schemaVersion: z.literal(AGENT_JOB_SCHEMA_VERSION),
|
|
8
|
+
idempotencyKey: durableReferenceSchema,
|
|
9
|
+
workspaceId: durableReferenceSchema,
|
|
10
|
+
sessionId: durableReferenceSchema,
|
|
11
|
+
taskRunId: uuidReferenceSchema,
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
14
|
+
export const AgentManagerJobDataSchema = agentJobBaseSchema
|
|
15
|
+
.safeExtend({
|
|
16
|
+
triggeredByMessageId: durableReferenceSchema.optional(),
|
|
17
|
+
clientRequestId: durableReferenceSchema.optional(),
|
|
18
|
+
})
|
|
19
|
+
.strict();
|
|
20
|
+
export const AgentExecutionJobDataSchema = agentJobBaseSchema
|
|
21
|
+
.safeExtend({
|
|
22
|
+
issueId: uuidReferenceSchema,
|
|
23
|
+
executionId: uuidReferenceSchema,
|
|
24
|
+
})
|
|
25
|
+
.strict();
|
|
26
|
+
export { buildExecutionJobIdentity, buildExecutionRetryRequestKey, buildManagerJobIdentity, validateExecutionJobIdentity, validateManagerJobIdentity, } from './identity.js';
|
|
27
|
+
/** @deprecated Prefer buildExecutionRetryRequestKey from identity.js */
|
|
28
|
+
export function buildExecutionRetryKeys(executionId) {
|
|
29
|
+
return {
|
|
30
|
+
dispatchKey: `agent-execution-retry:${executionId.trim()}`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { isPortalAgentLegacyRunTaskEnabled } from './legacy-run-task.js';
|
|
34
|
+
export { isPortalAgentLegacyHttpGoneEnabled } from './legacy-http-gone.js';
|
|
35
|
+
export { isPortalAgentRuntimeV2Enabled } from './runtime-v2.js';
|
|
36
|
+
export { isPortalAgentSandboxTeamMountEnabled } from './portal-sandbox-team-mount.js';
|
|
37
|
+
export { PORTAL_AGENT_DB_LEASE_MS, PORTAL_AGENT_HEARTBEAT_INTERVAL_MS, PORTAL_AGENT_REDIS_SLOT_TTL_MS, PORTAL_AGENT_SESSION_MUTEX_TTL_MS, PORTAL_AGENT_BULLMQ_LOCK_DURATION_MS, PORTAL_AGENT_BULLMQ_STALLED_INTERVAL_MS, PORTAL_AGENT_RUNTIME_TIMING, } from './runtime-timing.js';
|
|
38
|
+
export { noopAgentRuntimeMetrics, createLoggingAgentRuntimeMetrics, } from './runtime-metrics.js';
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent-jobs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAU,CAAC;AAEnD,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACjE,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAErC,MAAM,kBAAkB,GAAG,CAAC;KACzB,MAAM,CAAC;IACN,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAAC;IAClD,cAAc,EAAE,sBAAsB;IACtC,WAAW,EAAE,sBAAsB;IACnC,SAAS,EAAE,sBAAsB;IACjC,SAAS,EAAE,mBAAmB;CAC/B,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,CAAC,MAAM,yBAAyB,GAAG,kBAAkB;KACxD,UAAU,CAAC;IACV,oBAAoB,EAAE,sBAAsB,CAAC,QAAQ,EAAE;IACvD,eAAe,EAAE,sBAAsB,CAAC,QAAQ,EAAE;CACnD,CAAC;KACD,MAAM,EAAE,CAAC;AAIZ,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB;KAC1D,UAAU,CAAC;IACV,OAAO,EAAE,mBAAmB;IAC5B,WAAW,EAAE,mBAAmB;CACjC,CAAC;KACD,MAAM,EAAE,CAAC;AAIZ,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,EACvB,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,wEAAwE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