@oh-my-pi/pi-coding-agent 16.0.4 → 16.0.6
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/CHANGELOG.md +94 -0
- package/dist/cli.js +2027 -1396
- package/dist/types/advisor/advise-tool.d.ts +31 -19
- package/dist/types/autoresearch/tools/init-experiment.d.ts +13 -17
- package/dist/types/autoresearch/tools/log-experiment.d.ts +17 -19
- package/dist/types/autoresearch/tools/run-experiment.d.ts +3 -4
- package/dist/types/autoresearch/tools/update-notes.d.ts +4 -5
- package/dist/types/cli/args.d.ts +1 -0
- package/dist/types/cli/bench-cli.d.ts +6 -0
- package/dist/types/cli/ttsr-cli.d.ts +39 -0
- package/dist/types/commands/launch.d.ts +3 -0
- package/dist/types/commands/ttsr.d.ts +57 -0
- package/dist/types/commit/agentic/tools/analyze-file.d.ts +4 -5
- package/dist/types/commit/agentic/tools/git-file-diff.d.ts +4 -5
- package/dist/types/commit/agentic/tools/git-hunk.d.ts +5 -6
- package/dist/types/commit/agentic/tools/git-overview.d.ts +4 -5
- package/dist/types/commit/agentic/tools/propose-changelog.d.ts +23 -24
- package/dist/types/commit/agentic/tools/propose-commit.d.ts +11 -32
- package/dist/types/commit/agentic/tools/recent-commits.d.ts +3 -4
- package/dist/types/commit/agentic/tools/schemas.d.ts +6 -27
- package/dist/types/commit/agentic/tools/split-commit.d.ts +28 -49
- package/dist/types/commit/changelog/generate.d.ts +12 -13
- package/dist/types/commit/shared-llm.d.ts +10 -37
- package/dist/types/config/config-file.d.ts +4 -4
- package/dist/types/config/keybindings.d.ts +5 -0
- package/dist/types/config/models-config-schema.d.ts +625 -990
- package/dist/types/config/models-config.d.ts +229 -217
- package/dist/types/config/settings-schema.d.ts +144 -25
- package/dist/types/edit/hashline/params.d.ts +7 -11
- package/dist/types/edit/index.d.ts +2 -1
- package/dist/types/edit/modes/apply-patch.d.ts +4 -5
- package/dist/types/edit/modes/patch.d.ts +15 -24
- package/dist/types/edit/modes/replace.d.ts +16 -17
- package/dist/types/eval/js/index.d.ts +1 -0
- package/dist/types/extensibility/custom-commands/types.d.ts +6 -3
- package/dist/types/extensibility/custom-tools/types.d.ts +8 -5
- package/dist/types/extensibility/extensions/runner.d.ts +5 -2
- package/dist/types/extensibility/extensions/types.d.ts +14 -10
- package/dist/types/extensibility/hooks/types.d.ts +7 -4
- package/dist/types/extensibility/legacy-pi-ai-shim.d.ts +13 -5
- package/dist/types/extensibility/legacy-pi-coding-agent-shim.d.ts +17 -0
- package/dist/types/extensibility/shared-events.d.ts +22 -1
- package/dist/types/extensibility/typebox.d.ts +80 -58
- package/dist/types/goals/tools/goal-tool.d.ts +11 -24
- package/dist/types/index.d.ts +2 -0
- package/dist/types/lsp/index.d.ts +11 -26
- package/dist/types/lsp/types.d.ts +12 -28
- package/dist/types/main.d.ts +1 -0
- package/dist/types/mcp/client.d.ts +8 -0
- package/dist/types/modes/components/btw-panel.d.ts +1 -0
- package/dist/types/modes/components/custom-editor.d.ts +3 -1
- package/dist/types/modes/components/status-line/component.d.ts +1 -1
- package/dist/types/modes/components/status-line/context-thresholds.d.ts +0 -1
- package/dist/types/modes/controllers/btw-controller.d.ts +2 -0
- package/dist/types/modes/controllers/input-controller.d.ts +1 -0
- package/dist/types/modes/interactive-mode.d.ts +3 -0
- package/dist/types/modes/rpc/rpc-types.d.ts +1 -1
- package/dist/types/modes/setup-wizard/index.d.ts +1 -0
- package/dist/types/modes/setup-wizard/startup-splash.d.ts +7 -0
- package/dist/types/modes/theme/theme.d.ts +1 -1
- package/dist/types/modes/types.d.ts +3 -0
- package/dist/types/modes/utils/context-usage.d.ts +12 -0
- package/dist/types/sdk.d.ts +8 -1
- package/dist/types/session/agent-session.d.ts +24 -0
- package/dist/types/session/session-persistence.d.ts +4 -0
- package/dist/types/startup-splash.d.ts +12 -0
- package/dist/types/task/types.d.ts +47 -48
- package/dist/types/tools/ask.d.ts +26 -27
- package/dist/types/tools/ast-edit.d.ts +17 -17
- package/dist/types/tools/ast-grep.d.ts +12 -13
- package/dist/types/tools/bash.d.ts +20 -17
- package/dist/types/tools/browser.d.ts +46 -71
- package/dist/types/tools/checkpoint.d.ts +14 -15
- package/dist/types/tools/debug.d.ts +82 -145
- package/dist/types/tools/eval.d.ts +30 -40
- package/dist/types/tools/find.d.ts +17 -18
- package/dist/types/tools/gh.d.ts +49 -78
- package/dist/types/tools/image-gen.d.ts +20 -36
- package/dist/types/tools/inspect-image.d.ts +10 -11
- package/dist/types/tools/irc.d.ts +22 -33
- package/dist/types/tools/job.d.ts +11 -12
- package/dist/types/tools/learn.d.ts +21 -28
- package/dist/types/tools/manage-skill.d.ts +13 -22
- package/dist/types/tools/memory-edit.d.ts +15 -24
- package/dist/types/tools/memory-recall.d.ts +7 -8
- package/dist/types/tools/memory-reflect.d.ts +9 -10
- package/dist/types/tools/memory-retain.d.ts +13 -14
- package/dist/types/tools/read.d.ts +8 -8
- package/dist/types/tools/resolve.d.ts +11 -18
- package/dist/types/tools/review.d.ts +9 -15
- package/dist/types/tools/search-tool-bm25.d.ts +9 -10
- package/dist/types/tools/search.d.ts +16 -17
- package/dist/types/tools/ssh.d.ts +14 -15
- package/dist/types/tools/todo.d.ts +27 -43
- package/dist/types/tools/tts.d.ts +8 -9
- package/dist/types/tools/write.d.ts +9 -10
- package/dist/types/tui/code-cell.d.ts +2 -0
- package/dist/types/tui/index.d.ts +1 -0
- package/dist/types/tui/width-aware-text.d.ts +23 -0
- package/dist/types/utils/image-vision-fallback.d.ts +28 -0
- package/dist/types/utils/markit.d.ts +10 -1
- package/dist/types/web/search/index.d.ts +17 -28
- package/dist/types/web/search/providers/base.d.ts +1 -0
- package/dist/types/web/search/providers/gemini.d.ts +1 -0
- package/dist/types/web/search/providers/perplexity.d.ts +0 -2
- package/dist/types/web/search/types.d.ts +32 -26
- package/package.json +14 -13
- package/scripts/omp +1 -1
- package/src/advisor/__tests__/advisor.test.ts +103 -1
- package/src/advisor/advise-tool.ts +47 -11
- package/src/autoresearch/tools/init-experiment.ts +13 -16
- package/src/autoresearch/tools/log-experiment.ts +15 -18
- package/src/autoresearch/tools/run-experiment.ts +3 -3
- package/src/autoresearch/tools/update-notes.ts +4 -4
- package/src/cli/args.ts +1 -0
- package/src/cli/bench-cli.ts +30 -7
- package/src/cli/flag-tables.ts +8 -0
- package/src/cli/ttsr-cli.ts +995 -0
- package/src/cli-commands.ts +1 -0
- package/src/cli.ts +7 -1
- package/src/collab/host.ts +2 -2
- package/src/commands/launch.ts +3 -0
- package/src/commands/ttsr.ts +125 -0
- package/src/commit/agentic/tools/analyze-file.ts +4 -4
- package/src/commit/agentic/tools/git-file-diff.ts +4 -4
- package/src/commit/agentic/tools/git-hunk.ts +7 -5
- package/src/commit/agentic/tools/git-overview.ts +4 -4
- package/src/commit/agentic/tools/propose-changelog.ts +18 -15
- package/src/commit/agentic/tools/propose-commit.ts +6 -6
- package/src/commit/agentic/tools/recent-commits.ts +3 -3
- package/src/commit/agentic/tools/schemas.ts +8 -20
- package/src/commit/agentic/tools/split-commit.ts +19 -23
- package/src/commit/analysis/summary.ts +7 -5
- package/src/commit/changelog/generate.ts +15 -11
- package/src/commit/shared-llm.ts +17 -24
- package/src/config/config-file.ts +13 -15
- package/src/config/keybindings.ts +6 -0
- package/src/config/models-config-schema.ts +206 -179
- package/src/config/settings-schema.ts +118 -2
- package/src/discovery/builtin-rules/index.ts +2 -0
- package/src/discovery/builtin-rules/ts-import-type.md +2 -2
- package/src/discovery/builtin-rules/ts-no-any.md +11 -2
- package/src/discovery/builtin-rules/ts-no-inline-cast-access.md +55 -0
- package/src/edit/hashline/params.ts +12 -11
- package/src/edit/index.ts +5 -4
- package/src/edit/modes/apply-patch.ts +4 -4
- package/src/edit/modes/patch.ts +15 -18
- package/src/edit/modes/replace.ts +13 -17
- package/src/edit/renderer.ts +0 -1
- package/src/eval/agent-bridge.ts +11 -13
- package/src/eval/completion-bridge.ts +25 -17
- package/src/eval/js/context-manager.ts +17 -2
- package/src/eval/js/index.ts +1 -1
- package/src/eval/py/executor.ts +2 -2
- package/src/eval/py/runner.py +44 -0
- package/src/extensibility/custom-commands/loader.ts +5 -3
- package/src/extensibility/custom-commands/types.ts +6 -3
- package/src/extensibility/custom-tools/loader.ts +4 -2
- package/src/extensibility/custom-tools/types.ts +8 -5
- package/src/extensibility/extensions/loader.ts +4 -2
- package/src/extensibility/extensions/runner.ts +20 -2
- package/src/extensibility/extensions/types.ts +22 -8
- package/src/extensibility/hooks/loader.ts +5 -2
- package/src/extensibility/hooks/types.ts +7 -4
- package/src/extensibility/legacy-pi-ai-shim.ts +42 -5
- package/src/extensibility/legacy-pi-coding-agent-shim.ts +113 -0
- package/src/extensibility/plugins/legacy-pi-compat.ts +13 -13
- package/src/extensibility/shared-events.ts +24 -0
- package/src/extensibility/tool-proxy.ts +4 -1
- package/src/extensibility/typebox.ts +778 -251
- package/src/goals/guided-setup.ts +12 -3
- package/src/goals/tools/goal-tool.ts +6 -6
- package/src/index.ts +2 -0
- package/src/internal-urls/docs-index.generated.ts +15 -13
- package/src/lsp/types.ts +13 -27
- package/src/main.ts +29 -21
- package/src/mcp/client.ts +38 -13
- package/src/mcp/render.ts +102 -89
- package/src/modes/components/agent-hub.ts +11 -4
- package/src/modes/components/branch-summary-message.ts +1 -0
- package/src/modes/components/btw-panel.ts +5 -1
- package/src/modes/components/collab-prompt-message.ts +9 -7
- package/src/modes/components/compaction-summary-message.ts +1 -0
- package/src/modes/components/custom-editor.ts +18 -0
- package/src/modes/components/custom-message.ts +1 -0
- package/src/modes/components/footer.ts +6 -5
- package/src/modes/components/hook-message.ts +1 -0
- package/src/modes/components/read-tool-group.ts +9 -3
- package/src/modes/components/skill-message.ts +1 -0
- package/src/modes/components/status-line/component.ts +139 -15
- package/src/modes/components/status-line/context-thresholds.ts +0 -1
- package/src/modes/components/todo-reminder.ts +1 -0
- package/src/modes/components/tool-execution.ts +17 -10
- package/src/modes/components/ttsr-notification.ts +1 -0
- package/src/modes/components/user-message.ts +6 -6
- package/src/modes/controllers/btw-controller.ts +69 -1
- package/src/modes/controllers/event-controller.ts +2 -7
- package/src/modes/controllers/input-controller.ts +29 -0
- package/src/modes/controllers/selector-controller.ts +10 -3
- package/src/modes/interactive-mode.ts +42 -10
- package/src/modes/rpc/rpc-types.ts +1 -1
- package/src/modes/setup-wizard/index.ts +1 -0
- package/src/modes/setup-wizard/scenes/sign-in.ts +77 -5
- package/src/modes/setup-wizard/startup-splash.ts +107 -0
- package/src/modes/theme/theme.ts +133 -143
- package/src/modes/types.ts +3 -0
- package/src/modes/utils/context-usage.ts +37 -20
- package/src/modes/utils/hotkeys-markdown.ts +1 -0
- package/src/prompts/system/system-prompt.md +1 -0
- package/src/prompts/tools/image-attachment-describe-system.md +8 -0
- package/src/prompts/tools/image-attachment-describe.md +10 -0
- package/src/sdk.ts +35 -22
- package/src/session/agent-session.ts +715 -255
- package/src/session/session-history-format.ts +11 -2
- package/src/session/session-loader.ts +19 -32
- package/src/session/session-persistence.ts +27 -11
- package/src/session/snapcompact-inline.ts +1 -1
- package/src/slash-commands/builtin-registry.ts +4 -11
- package/src/ssh/connection-manager.ts +3 -2
- package/src/startup-splash.ts +19 -0
- package/src/task/executor.ts +12 -7
- package/src/task/types.ts +44 -41
- package/src/tool-discovery/tool-index.ts +17 -4
- package/src/tools/ask.ts +14 -14
- package/src/tools/ast-edit.ts +17 -14
- package/src/tools/ast-grep.ts +10 -9
- package/src/tools/bash.ts +15 -10
- package/src/tools/browser/launch.ts +13 -0
- package/src/tools/browser.ts +26 -32
- package/src/tools/checkpoint.ts +7 -7
- package/src/tools/debug.ts +72 -69
- package/src/tools/eval.ts +18 -19
- package/src/tools/find.ts +20 -13
- package/src/tools/gh.ts +29 -49
- package/src/tools/image-gen.ts +94 -57
- package/src/tools/inspect-image.ts +8 -9
- package/src/tools/irc.ts +12 -12
- package/src/tools/job.ts +6 -6
- package/src/tools/learn.ts +11 -14
- package/src/tools/manage-skill.ts +19 -23
- package/src/tools/memory-edit.ts +8 -8
- package/src/tools/memory-recall.ts +4 -4
- package/src/tools/memory-reflect.ts +5 -5
- package/src/tools/memory-retain.ts +9 -11
- package/src/tools/puppeteer/02_stealth_hairline.txt +1 -1
- package/src/tools/puppeteer/04_stealth_iframe.txt +4 -4
- package/src/tools/puppeteer/05_stealth_webgl.txt +1 -1
- package/src/tools/puppeteer/10_stealth_plugins.txt +6 -4
- package/src/tools/puppeteer/12_stealth_codecs.txt +2 -2
- package/src/tools/puppeteer/13_stealth_worker.txt +1 -1
- package/src/tools/read.ts +197 -19
- package/src/tools/report-tool-issue.ts +6 -6
- package/src/tools/resolve.ts +6 -6
- package/src/tools/review.ts +10 -12
- package/src/tools/search-tool-bm25.ts +5 -5
- package/src/tools/search.ts +20 -29
- package/src/tools/ssh.ts +8 -8
- package/src/tools/todo.ts +16 -19
- package/src/tools/tts.ts +16 -15
- package/src/tools/write.ts +5 -5
- package/src/tui/code-cell.ts +44 -3
- package/src/tui/index.ts +1 -0
- package/src/tui/width-aware-text.ts +58 -0
- package/src/utils/image-vision-fallback.ts +197 -0
- package/src/utils/markit.ts +17 -2
- package/src/web/search/index.ts +21 -9
- package/src/web/search/providers/base.ts +1 -0
- package/src/web/search/providers/gemini.ts +56 -18
- package/src/web/search/providers/perplexity.ts +373 -126
- package/src/web/search/types.ts +28 -48
package/src/tools/image-gen.ts
CHANGED
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
Snowflake,
|
|
20
20
|
untilAborted,
|
|
21
21
|
} from "@oh-my-pi/pi-utils";
|
|
22
|
-
import {
|
|
22
|
+
import { type } from "arktype";
|
|
23
23
|
import packageJson from "../../package.json" with { type: "json" };
|
|
24
|
-
|
|
25
24
|
import { isAuthenticated, type ModelRegistry } from "../config/model-registry";
|
|
25
|
+
import { settings } from "../config/settings";
|
|
26
26
|
import type { CustomTool } from "../extensibility/custom-tools/types";
|
|
27
27
|
import { ohMyPiXAIUserAgent, resolveXAIHttpCredentials } from "../lib/xai-http";
|
|
28
28
|
import imageGenDescription from "../prompts/tools/image-gen.md" with { type: "text" };
|
|
@@ -38,7 +38,8 @@ const DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
|
38
38
|
const OPENAI_IMAGE_OUTPUT_FORMAT = "webp";
|
|
39
39
|
const OPENAI_IMAGE_MIME_TYPE = "image/webp";
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const DEFAULT_ANTIGRAVITY_ENDPOINT_PROD = "https://daily-cloudcode-pa.googleapis.com";
|
|
42
|
+
const DEFAULT_ANTIGRAVITY_ENDPOINT_SANDBOX = "https://daily-cloudcode-pa.sandbox.googleapis.com";
|
|
42
43
|
const IMAGE_SYSTEM_INSTRUCTION =
|
|
43
44
|
"You are an AI image generator. Generate images based on user descriptions. Focus on creating high-quality, visually appealing images that match the user's request.";
|
|
44
45
|
|
|
@@ -57,37 +58,32 @@ const XAI_IMAGE_ASPECT_RATIOS = [...COMMON_IMAGE_ASPECT_RATIOS, "3:2", "2:3"] as
|
|
|
57
58
|
const COMMON_IMAGE_ASPECT_RATIO_SET = new Set<string>(COMMON_IMAGE_ASPECT_RATIOS);
|
|
58
59
|
const IMAGE_PROVIDER_PREFERENCES = new Set<string>(["auto", "antigravity", "gemini", "openai", "openrouter", "xai"]);
|
|
59
60
|
|
|
60
|
-
const responseModalitySchema =
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.strict();
|
|
87
|
-
|
|
88
|
-
export const imageGenSchema = baseImageSchema;
|
|
89
|
-
export type ImageGenParams = z.infer<typeof imageGenSchema>;
|
|
90
|
-
export type GeminiResponseModality = z.infer<typeof responseModalitySchema>;
|
|
61
|
+
const responseModalitySchema = type('"IMAGE" | "TEXT"');
|
|
62
|
+
|
|
63
|
+
const aspectRatioSchema = type.enumerated(...XAI_IMAGE_ASPECT_RATIOS).describe("aspect ratio");
|
|
64
|
+
const imageSizeSchema = type('"1024x1024" | "1536x1024" | "1024x1536"').describe("image size");
|
|
65
|
+
|
|
66
|
+
const inputImageSchema = type({
|
|
67
|
+
"path?": type("string").describe("input image path"),
|
|
68
|
+
"data?": type("string").describe("base64 image data"),
|
|
69
|
+
"mime_type?": type("string").describe("mime type"),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const imageGenSchema = type({
|
|
73
|
+
subject: type("string").describe("main subject"),
|
|
74
|
+
"action?": type("string").describe("what subject is doing"),
|
|
75
|
+
"scene?": type("string").describe("location or environment"),
|
|
76
|
+
"composition?": type("string").describe("camera angle and framing"),
|
|
77
|
+
"lighting?": type("string").describe("lighting setup"),
|
|
78
|
+
"style?": type("string").describe("artistic style"),
|
|
79
|
+
"text?": type("string").describe("text to render"),
|
|
80
|
+
"changes?": type("string[]").describe("edits to make"),
|
|
81
|
+
"aspect_ratio?": aspectRatioSchema,
|
|
82
|
+
"image_size?": imageSizeSchema,
|
|
83
|
+
"input?": inputImageSchema.array().describe("input images"),
|
|
84
|
+
});
|
|
85
|
+
export type ImageGenParams = typeof imageGenSchema.infer;
|
|
86
|
+
export type GeminiResponseModality = typeof responseModalitySchema.infer;
|
|
91
87
|
|
|
92
88
|
/**
|
|
93
89
|
* Assembles a structured prompt from the provided parameters.
|
|
@@ -1164,33 +1160,74 @@ export const imageGenTool: CustomTool<typeof imageGenSchema, ImageGenToolDetails
|
|
|
1164
1160
|
resolvedImages,
|
|
1165
1161
|
);
|
|
1166
1162
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
}
|
|
1163
|
+
let endpoints = [DEFAULT_ANTIGRAVITY_ENDPOINT_PROD, DEFAULT_ANTIGRAVITY_ENDPOINT_SANDBOX];
|
|
1164
|
+
try {
|
|
1165
|
+
const mode = settings.get("providers.antigravityEndpoint");
|
|
1166
|
+
if (mode === "production") {
|
|
1167
|
+
endpoints = [DEFAULT_ANTIGRAVITY_ENDPOINT_PROD];
|
|
1168
|
+
} else if (mode === "sandbox") {
|
|
1169
|
+
endpoints = [DEFAULT_ANTIGRAVITY_ENDPOINT_SANDBOX];
|
|
1170
|
+
}
|
|
1171
|
+
} catch {
|
|
1172
|
+
// Ignored
|
|
1173
|
+
}
|
|
1178
1174
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1175
|
+
let resp: Response | undefined;
|
|
1176
|
+
let lastError: Error | undefined;
|
|
1177
|
+
|
|
1178
|
+
for (let i = 0; i < endpoints.length; i++) {
|
|
1179
|
+
const endpoint = endpoints[i];
|
|
1180
|
+
const isLastEndpoint = i === endpoints.length - 1;
|
|
1182
1181
|
try {
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1182
|
+
resp = await fetchImpl(`${endpoint}/v1internal:streamGenerateContent?alt=sse`, {
|
|
1183
|
+
method: "POST",
|
|
1184
|
+
headers: {
|
|
1185
|
+
Authorization: `Bearer ${bearer}`,
|
|
1186
|
+
"Content-Type": "application/json",
|
|
1187
|
+
Accept: "text/event-stream",
|
|
1188
|
+
"User-Agent": getAntigravityUserAgent(),
|
|
1189
|
+
},
|
|
1190
|
+
body: JSON.stringify(requestBody),
|
|
1191
|
+
signal: requestSignal,
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1194
|
+
if (resp.ok) {
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
const errorText = await resp.text();
|
|
1199
|
+
let message = errorText;
|
|
1200
|
+
try {
|
|
1201
|
+
const parsedErr = JSON.parse(errorText) as { error?: { message?: string } };
|
|
1202
|
+
message = parsedErr.error?.message ?? message;
|
|
1203
|
+
} catch {
|
|
1204
|
+
// Keep raw text.
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
lastError = new ProviderHttpError(
|
|
1208
|
+
`Antigravity image request failed (${resp.status}): ${message}`,
|
|
1209
|
+
resp.status,
|
|
1210
|
+
{ headers: resp.headers },
|
|
1211
|
+
);
|
|
1212
|
+
|
|
1213
|
+
if (resp.status === 429 || (resp.status >= 500 && resp.status < 600)) {
|
|
1214
|
+
if (!isLastEndpoint) {
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
break;
|
|
1219
|
+
} catch (error) {
|
|
1220
|
+
lastError = error as Error;
|
|
1221
|
+
if (isLastEndpoint) {
|
|
1222
|
+
break;
|
|
1223
|
+
}
|
|
1187
1224
|
}
|
|
1188
|
-
throw new ProviderHttpError(
|
|
1189
|
-
`Antigravity image request failed (${resp.status}): ${message}`,
|
|
1190
|
-
resp.status,
|
|
1191
|
-
{ headers: resp.headers },
|
|
1192
|
-
);
|
|
1193
1225
|
}
|
|
1226
|
+
|
|
1227
|
+
if (!resp?.ok) {
|
|
1228
|
+
throw lastError ?? new Error("Antigravity image generation failed");
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1194
1231
|
return resp;
|
|
1195
1232
|
},
|
|
1196
1233
|
{ signal: requestSignal },
|
|
@@ -2,7 +2,7 @@ import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallb
|
|
|
2
2
|
import { instrumentedCompleteSimple, resolveTelemetry } from "@oh-my-pi/pi-agent-core";
|
|
3
3
|
import { type Api, completeSimple, type Model, type ToolExample } from "@oh-my-pi/pi-ai";
|
|
4
4
|
import { prompt } from "@oh-my-pi/pi-utils";
|
|
5
|
-
import {
|
|
5
|
+
import { type } from "arktype";
|
|
6
6
|
import { extractTextContent } from "../commit/utils";
|
|
7
7
|
|
|
8
8
|
import { expandRoleAlias, getModelMatchPreferences, resolveModelFromString } from "../config/model-resolver";
|
|
@@ -18,14 +18,13 @@ import {
|
|
|
18
18
|
import type { ToolSession } from "./index";
|
|
19
19
|
import { ToolError } from "./tool-errors";
|
|
20
20
|
|
|
21
|
-
const inspectImageSchema =
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.strict();
|
|
21
|
+
const inspectImageSchema = type({
|
|
22
|
+
path: type("string").describe("image path"),
|
|
23
|
+
question: type("string").describe("question about image"),
|
|
24
|
+
"+": "reject",
|
|
25
|
+
});
|
|
27
26
|
|
|
28
|
-
export type InspectImageParams =
|
|
27
|
+
export type InspectImageParams = typeof inspectImageSchema.infer;
|
|
29
28
|
|
|
30
29
|
export interface InspectImageToolDetails {
|
|
31
30
|
model: string;
|
|
@@ -43,7 +42,7 @@ export class InspectImageTool implements AgentTool<typeof inspectImageSchema, In
|
|
|
43
42
|
readonly parameters = inspectImageSchema;
|
|
44
43
|
readonly strict = false;
|
|
45
44
|
|
|
46
|
-
readonly examples: readonly ToolExample<
|
|
45
|
+
readonly examples: readonly ToolExample<typeof inspectImageSchema.infer>[] = [
|
|
47
46
|
{
|
|
48
47
|
caption: "OCR with strict formatting",
|
|
49
48
|
call: {
|
package/src/tools/irc.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallb
|
|
|
13
13
|
import type { ToolExample } from "@oh-my-pi/pi-ai";
|
|
14
14
|
import { type Component, Text } from "@oh-my-pi/pi-tui";
|
|
15
15
|
import { formatAge, formatDuration, prompt } from "@oh-my-pi/pi-utils";
|
|
16
|
-
import {
|
|
16
|
+
import { type } from "arktype";
|
|
17
17
|
import type { Settings } from "../config/settings";
|
|
18
18
|
import type { RenderResultOptions } from "../extensibility/custom-tools/types";
|
|
19
19
|
import { IrcBus, type IrcDeliveryReceipt, type IrcMessage } from "../irc/bus";
|
|
@@ -49,18 +49,18 @@ export function isIrcEnabled(settings: Settings, taskDepth: number): boolean {
|
|
|
49
49
|
return canSpawnAtDepth(maxDepth, taskDepth);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const ircSchema =
|
|
53
|
-
op:
|
|
54
|
-
to:
|
|
55
|
-
message:
|
|
56
|
-
replyTo:
|
|
57
|
-
await:
|
|
58
|
-
from:
|
|
59
|
-
timeoutMs:
|
|
60
|
-
peek:
|
|
52
|
+
const ircSchema = type({
|
|
53
|
+
op: type("'send' | 'wait' | 'inbox' | 'list'").describe("irc operation"),
|
|
54
|
+
"to?": type("string").describe('send: recipient agent id or "all"'),
|
|
55
|
+
"message?": type("string").describe("send: message body"),
|
|
56
|
+
"replyTo?": type("string").describe("send: message id being answered"),
|
|
57
|
+
"await?": type("boolean").describe('send: wait for the recipient\'s reply (invalid with to:"all")'),
|
|
58
|
+
"from?": type("string").describe("wait: only accept a message from this agent id"),
|
|
59
|
+
"timeoutMs?": type("number").describe("wait: timeout in milliseconds (0 waits indefinitely)"),
|
|
60
|
+
"peek?": type("boolean").describe("inbox: list messages without consuming them"),
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
type IrcParams =
|
|
63
|
+
type IrcParams = typeof ircSchema.infer;
|
|
64
64
|
|
|
65
65
|
interface IrcPeerInfo {
|
|
66
66
|
id: string;
|
|
@@ -98,7 +98,7 @@ export class IrcTool implements AgentTool<typeof ircSchema, IrcDetails> {
|
|
|
98
98
|
readonly parameters = ircSchema;
|
|
99
99
|
readonly strict = true;
|
|
100
100
|
|
|
101
|
-
readonly examples: readonly ToolExample<
|
|
101
|
+
readonly examples: readonly ToolExample<typeof ircSchema.infer>[] = [
|
|
102
102
|
{
|
|
103
103
|
caption: "List peers",
|
|
104
104
|
call: { op: "list" },
|
package/src/tools/job.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallb
|
|
|
2
2
|
import type { Component } from "@oh-my-pi/pi-tui";
|
|
3
3
|
import { Text } from "@oh-my-pi/pi-tui";
|
|
4
4
|
import { prompt } from "@oh-my-pi/pi-utils";
|
|
5
|
-
import {
|
|
5
|
+
import { type } from "arktype";
|
|
6
6
|
import type { AsyncJob, AsyncJobManager } from "../async";
|
|
7
7
|
import type { RenderResultOptions } from "../extensibility/custom-tools/types";
|
|
8
8
|
import { shimmerEnabled, shimmerText } from "../modes/theme/shimmer";
|
|
@@ -23,13 +23,13 @@ import {
|
|
|
23
23
|
} from "./render-utils";
|
|
24
24
|
import { ToolError } from "./tool-errors";
|
|
25
25
|
|
|
26
|
-
const jobSchema =
|
|
27
|
-
poll:
|
|
28
|
-
cancel:
|
|
29
|
-
list:
|
|
26
|
+
const jobSchema = type({
|
|
27
|
+
"poll?": type("string[]").describe("job ids to wait for; omit to wait on all running jobs"),
|
|
28
|
+
"cancel?": type("string[]").describe("job ids to cancel"),
|
|
29
|
+
"list?": type("boolean").describe("snapshot all jobs"),
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
type JobParams =
|
|
32
|
+
type JobParams = typeof jobSchema.infer;
|
|
33
33
|
|
|
34
34
|
const WAIT_DURATION_MS: Record<string, number> = {
|
|
35
35
|
"5s": 5_000,
|
package/src/tools/learn.ts
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core";
|
|
2
|
-
import {
|
|
2
|
+
import { type } from "arktype";
|
|
3
3
|
import { sanitizeSkillName, writeManagedSkill } from "../autolearn/managed-skills";
|
|
4
4
|
import { isNameClaimedByAuthoredSkill } from "../extensibility/skills";
|
|
5
5
|
import { localBackend } from "../memory-backend/local-backend";
|
|
6
6
|
import learnDescription from "../prompts/tools/learn.md" with { type: "text" };
|
|
7
7
|
import type { ToolSession } from ".";
|
|
8
8
|
|
|
9
|
-
const learnSchema =
|
|
10
|
-
memory:
|
|
11
|
-
context:
|
|
12
|
-
skill:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
19
|
-
.describe("also create or enhance a managed skill in the same call")
|
|
20
|
-
.optional(),
|
|
9
|
+
const learnSchema = type({
|
|
10
|
+
memory: type("string").describe("the durable, self-contained lesson to remember (what, when, why)"),
|
|
11
|
+
"context?": type("string").describe("optional source context for the lesson"),
|
|
12
|
+
"skill?": type({
|
|
13
|
+
action: "'create' | 'update'",
|
|
14
|
+
name: type("string").describe("kebab-case skill name"),
|
|
15
|
+
description: type("string").describe("one-line description of when to use the skill"),
|
|
16
|
+
body: type("string").describe("the SKILL.md body in markdown (no frontmatter)"),
|
|
17
|
+
}).describe("also create or enhance a managed skill in the same call"),
|
|
21
18
|
});
|
|
22
19
|
|
|
23
|
-
export type LearnParams =
|
|
20
|
+
export type LearnParams = typeof learnSchema.infer;
|
|
24
21
|
|
|
25
22
|
/**
|
|
26
23
|
* Orchestrating "learn" tool: persists a lesson to long-term memory and,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core";
|
|
3
|
-
import {
|
|
3
|
+
import { type } from "arktype";
|
|
4
4
|
import {
|
|
5
5
|
deleteManagedSkill,
|
|
6
6
|
getManagedSkillsDir,
|
|
@@ -11,29 +11,25 @@ import { isNameClaimedByAuthoredSkill } from "../extensibility/skills";
|
|
|
11
11
|
import manageSkillDescription from "../prompts/tools/manage-skill.md" with { type: "text" };
|
|
12
12
|
import type { ToolSession } from ".";
|
|
13
13
|
|
|
14
|
-
const manageSkillSchema =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
description
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.refine(p => p.action === "delete" || (p.description !== undefined && p.body !== undefined), {
|
|
32
|
-
message: '"create" and "update" require both "description" and "body".',
|
|
33
|
-
path: ["description"],
|
|
34
|
-
});
|
|
14
|
+
const manageSkillSchema = type({
|
|
15
|
+
action: "'create' | 'update' | 'delete'",
|
|
16
|
+
name: type("string").describe("kebab-case skill name"),
|
|
17
|
+
"description?": type("string").describe(
|
|
18
|
+
"one-line description of when to use the skill (required for create/update)",
|
|
19
|
+
),
|
|
20
|
+
"body?": type("string").describe("the SKILL.md body in markdown, no frontmatter (required for create/update)"),
|
|
21
|
+
}).narrow(
|
|
22
|
+
(p, ctx) =>
|
|
23
|
+
p.action === "delete" ||
|
|
24
|
+
(p.description !== undefined && p.body !== undefined) ||
|
|
25
|
+
// Enforce the action/field contract at validation time rather than only in
|
|
26
|
+
// execute. Kept as a cross-field narrow (not a discriminated union) so the
|
|
27
|
+
// wire schema stays a single root object — strict structured-output mode and
|
|
28
|
+
// the Anthropic tool-schema builder both require that.
|
|
29
|
+
ctx.mustBe('used with both "description" and "body" for "create" and "update"'),
|
|
30
|
+
);
|
|
35
31
|
|
|
36
|
-
export type ManageSkillParams =
|
|
32
|
+
export type ManageSkillParams = typeof manageSkillSchema.infer;
|
|
37
33
|
|
|
38
34
|
/**
|
|
39
35
|
* Direct create/update/delete of isolated managed skills. Gated behind
|
package/src/tools/memory-edit.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core";
|
|
2
|
-
import {
|
|
2
|
+
import { type } from "arktype";
|
|
3
3
|
import memoryEditDescription from "../prompts/tools/memory-edit.md" with { type: "text" };
|
|
4
4
|
import type { ToolSession } from ".";
|
|
5
5
|
|
|
6
|
-
const memoryEditSchema =
|
|
7
|
-
op:
|
|
8
|
-
id:
|
|
9
|
-
content:
|
|
10
|
-
importance:
|
|
11
|
-
replacement_id:
|
|
6
|
+
const memoryEditSchema = type({
|
|
7
|
+
op: type("'update' | 'forget' | 'invalidate'").describe("memory edit operation"),
|
|
8
|
+
id: type("string").describe("memory id from recall output"),
|
|
9
|
+
"content?": type("string").describe("replacement content for update"),
|
|
10
|
+
"importance?": type("number").describe("replacement importance for update, clamped to [0, 1]"),
|
|
11
|
+
"replacement_id?": type("string").describe("replacement memory id for invalidate"),
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
export type MemoryEditParams =
|
|
14
|
+
export type MemoryEditParams = typeof memoryEditSchema.infer;
|
|
15
15
|
|
|
16
16
|
export class MemoryEditTool implements AgentTool<typeof memoryEditSchema> {
|
|
17
17
|
readonly name = "memory_edit";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core";
|
|
2
2
|
import { logger, untilAborted } from "@oh-my-pi/pi-utils";
|
|
3
|
-
import {
|
|
3
|
+
import { type } from "arktype";
|
|
4
4
|
import { formatCurrentTime, formatMemories } from "../hindsight/content";
|
|
5
5
|
import recallDescription from "../prompts/tools/recall.md" with { type: "text" };
|
|
6
6
|
import type { ToolSession } from ".";
|
|
7
7
|
|
|
8
|
-
const memoryRecallSchema =
|
|
9
|
-
query:
|
|
8
|
+
const memoryRecallSchema = type({
|
|
9
|
+
query: type("string").describe("natural language search query"),
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
export type MemoryRecallParams =
|
|
12
|
+
export type MemoryRecallParams = typeof memoryRecallSchema.infer;
|
|
13
13
|
|
|
14
14
|
export class MemoryRecallTool implements AgentTool<typeof memoryRecallSchema> {
|
|
15
15
|
readonly name = "recall";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core";
|
|
2
2
|
import { logger, untilAborted } from "@oh-my-pi/pi-utils";
|
|
3
|
-
import {
|
|
3
|
+
import { type } from "arktype";
|
|
4
4
|
import { ensureBankExists } from "../hindsight/bank";
|
|
5
5
|
import reflectDescription from "../prompts/tools/reflect.md" with { type: "text" };
|
|
6
6
|
import type { ToolSession } from ".";
|
|
7
7
|
|
|
8
|
-
const memoryReflectSchema =
|
|
9
|
-
query:
|
|
10
|
-
context:
|
|
8
|
+
const memoryReflectSchema = type({
|
|
9
|
+
query: type("string").describe("question to answer"),
|
|
10
|
+
"context?": type("string").describe("optional context"),
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
export type MemoryReflectParams =
|
|
13
|
+
export type MemoryReflectParams = typeof memoryReflectSchema.infer;
|
|
14
14
|
|
|
15
15
|
export class MemoryReflectTool implements AgentTool<typeof memoryReflectSchema> {
|
|
16
16
|
readonly name = "reflect";
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import type { AgentTool, AgentToolResult } from "@oh-my-pi/pi-agent-core";
|
|
2
|
-
import {
|
|
2
|
+
import { type } from "arktype";
|
|
3
3
|
import retainDescription from "../prompts/tools/retain.md" with { type: "text" };
|
|
4
4
|
import type { ToolSession } from ".";
|
|
5
5
|
|
|
6
|
-
const memoryRetainSchema =
|
|
7
|
-
items:
|
|
8
|
-
.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
14
|
-
.min(1)
|
|
6
|
+
const memoryRetainSchema = type({
|
|
7
|
+
items: type({
|
|
8
|
+
content: type("string").describe("information to remember"),
|
|
9
|
+
"context?": type("string").describe("source context"),
|
|
10
|
+
})
|
|
11
|
+
.array()
|
|
12
|
+
.atLeastLength(1)
|
|
15
13
|
.describe("memories to retain"),
|
|
16
14
|
});
|
|
17
15
|
|
|
18
|
-
export type MemoryRetainParams =
|
|
16
|
+
export type MemoryRetainParams = typeof memoryRetainSchema.infer;
|
|
19
17
|
export class MemoryRetainTool implements AgentTool<typeof memoryRetainSchema> {
|
|
20
18
|
readonly name = "retain";
|
|
21
19
|
readonly approval = "read" as const;
|
|
@@ -4,7 +4,7 @@ const addContentWindowProxy = (iframe) => {
|
|
|
4
4
|
if (key === "self") return this;
|
|
5
5
|
if (key === "frameElement") return iframe;
|
|
6
6
|
if (key === "0") return undefined;
|
|
7
|
-
return
|
|
7
|
+
return Reflect_get(target, key);
|
|
8
8
|
},
|
|
9
9
|
};
|
|
10
10
|
|
|
@@ -24,7 +24,7 @@ const addContentWindowProxy = (iframe) => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
const handleIframeCreation = (target, thisArg, args) => {
|
|
27
|
-
const iframe = target
|
|
27
|
+
const iframe = Reflect_apply(target, thisArg, args);
|
|
28
28
|
const originalIframe = iframe;
|
|
29
29
|
const originalSrcdoc = originalIframe.srcdoc;
|
|
30
30
|
|
|
@@ -53,12 +53,12 @@ const addIframeCreationSniffer = () => {
|
|
|
53
53
|
apply(target, thisArg, args) {
|
|
54
54
|
const isIframe = args && args.length && `${args[0]}`.toLowerCase() === "iframe";
|
|
55
55
|
if (!isIframe) {
|
|
56
|
-
return target
|
|
56
|
+
return Reflect_apply(target, thisArg, args);
|
|
57
57
|
}
|
|
58
58
|
return handleIframeCreation(target, thisArg, args);
|
|
59
59
|
},
|
|
60
60
|
get(target, key) {
|
|
61
|
-
return
|
|
61
|
+
return Reflect_get(target, key);
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
64
|
|
|
@@ -113,11 +113,13 @@ const generateMagicArray = (dataArray, proto, itemProto, itemMainProp) => {
|
|
|
113
113
|
const blacklist = [...Object_keys(data), "length", "enabledPlugin"];
|
|
114
114
|
return new Window_Proxy(obj, {
|
|
115
115
|
ownKeys(target) {
|
|
116
|
-
return
|
|
116
|
+
return [...Object_getOwnPropertyNames(target), ...Object.getOwnPropertySymbols(target)].filter(
|
|
117
|
+
key => !blacklist.includes(key),
|
|
118
|
+
);
|
|
117
119
|
},
|
|
118
120
|
getOwnPropertyDescriptor(target, prop) {
|
|
119
121
|
if (blacklist.includes(prop)) return undefined;
|
|
120
|
-
return
|
|
122
|
+
return Object_getOwnPropertyDescriptor(target, prop);
|
|
121
123
|
},
|
|
122
124
|
});
|
|
123
125
|
};
|
|
@@ -148,7 +150,7 @@ const generateMagicArray = (dataArray, proto, itemProto, itemMainProp) => {
|
|
|
148
150
|
if (key === "item") return functionMocks.item;
|
|
149
151
|
if (key === "namedItem") return functionMocks.namedItem;
|
|
150
152
|
if (proto === PluginArray.prototype && key === "refresh") return functionMocks.refresh;
|
|
151
|
-
return
|
|
153
|
+
return Reflect_get(target, key);
|
|
152
154
|
},
|
|
153
155
|
ownKeys(target) {
|
|
154
156
|
const keys = [];
|
|
@@ -159,7 +161,7 @@ const generateMagicArray = (dataArray, proto, itemProto, itemMainProp) => {
|
|
|
159
161
|
},
|
|
160
162
|
getOwnPropertyDescriptor(target, prop) {
|
|
161
163
|
if (prop === "length") return undefined;
|
|
162
|
-
return
|
|
164
|
+
return Object_getOwnPropertyDescriptor(target, prop);
|
|
163
165
|
},
|
|
164
166
|
});
|
|
165
167
|
};
|
|
@@ -19,7 +19,7 @@ Object_defineProperty(HTMLMediaElement.prototype, "canPlayType", {
|
|
|
19
19
|
value: new Window_Proxy(originalCanPlayType, {
|
|
20
20
|
apply(target, ctx, args) {
|
|
21
21
|
if (!args || !args.length) {
|
|
22
|
-
return target
|
|
22
|
+
return Reflect_apply(target, ctx, args);
|
|
23
23
|
}
|
|
24
24
|
const { mime, codecs } = parseInput(args[0]);
|
|
25
25
|
if (mime === "video/mp4" && codecs.includes("avc1.42E01E")) {
|
|
@@ -31,7 +31,7 @@ Object_defineProperty(HTMLMediaElement.prototype, "canPlayType", {
|
|
|
31
31
|
if (mime === "audio/aac" && !codecs.length) {
|
|
32
32
|
return "probably";
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
return Reflect_apply(target, ctx, args);
|
|
35
35
|
},
|
|
36
36
|
}),
|
|
37
37
|
writable: true,
|