opencode-ext-connector 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/LICENSE +29 -0
- package/README.md +207 -0
- package/THIRD_PARTY_NOTICES.md +201 -0
- package/dist/catalog/parse-ids.d.ts +2 -0
- package/dist/catalog/parse-ids.js +49 -0
- package/dist/core/adapter.d.ts +16 -0
- package/dist/core/adapter.js +20 -0
- package/dist/core/clock.d.ts +7 -0
- package/dist/core/clock.js +1 -0
- package/dist/core/deadline.d.ts +13 -0
- package/dist/core/deadline.js +54 -0
- package/dist/core/errors.d.ts +57 -0
- package/dist/core/errors.js +81 -0
- package/dist/core/health.d.ts +22 -0
- package/dist/core/health.js +30 -0
- package/dist/core/http.d.ts +28 -0
- package/dist/core/http.js +1 -0
- package/dist/core/ids.d.ts +7 -0
- package/dist/core/ids.js +23 -0
- package/dist/core/lifecycle.d.ts +4 -0
- package/dist/core/lifecycle.js +16 -0
- package/dist/core/logger.d.ts +21 -0
- package/dist/core/logger.js +61 -0
- package/dist/core/models.d.ts +41 -0
- package/dist/core/models.js +59 -0
- package/dist/core/options.d.ts +31 -0
- package/dist/core/options.js +62 -0
- package/dist/core/process.d.ts +20 -0
- package/dist/core/process.js +1 -0
- package/dist/http/fetch-transport.d.ts +2 -0
- package/dist/http/fetch-transport.js +75 -0
- package/dist/http/package-version.d.ts +7 -0
- package/dist/http/package-version.js +46 -0
- package/dist/http/read-body.d.ts +9 -0
- package/dist/http/read-body.js +22 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/logging/logger.d.ts +4 -0
- package/dist/logging/logger.js +11 -0
- package/dist/opencode/auth-store.d.ts +19 -0
- package/dist/opencode/auth-store.js +107 -0
- package/dist/opencode/beta-api.d.ts +3 -0
- package/dist/opencode/beta-api.js +1 -0
- package/dist/opencode/catalog-bridge.d.ts +3 -0
- package/dist/opencode/catalog-bridge.js +85 -0
- package/dist/opencode/health-refresh.d.ts +16 -0
- package/dist/opencode/health-refresh.js +49 -0
- package/dist/opencode/host-options.d.ts +2 -0
- package/dist/opencode/host-options.js +49 -0
- package/dist/opencode/language-factory.d.ts +13 -0
- package/dist/opencode/language-factory.js +37 -0
- package/dist/opencode/ollama-probe.d.ts +2 -0
- package/dist/opencode/ollama-probe.js +15 -0
- package/dist/opencode/ollama-production.d.ts +4 -0
- package/dist/opencode/ollama-production.js +10 -0
- package/dist/opencode/plugin.d.ts +33 -0
- package/dist/opencode/plugin.js +40 -0
- package/dist/opencode/process-exit.d.ts +4 -0
- package/dist/opencode/process-exit.js +22 -0
- package/dist/opencode/provider-entry.d.ts +25 -0
- package/dist/opencode/provider-entry.js +1 -0
- package/dist/opencode/providers.d.ts +16 -0
- package/dist/opencode/providers.js +140 -0
- package/dist/opencode/register-integrations.d.ts +3 -0
- package/dist/opencode/register-integrations.js +8 -0
- package/dist/opencode/reload.d.ts +9 -0
- package/dist/opencode/reload.js +30 -0
- package/dist/opencode/v1-anthropic-auth.d.ts +9 -0
- package/dist/opencode/v1-anthropic-auth.js +55 -0
- package/dist/opencode/v1-catalog.d.ts +13 -0
- package/dist/opencode/v1-catalog.js +80 -0
- package/dist/opencode/v1-language.d.ts +3 -0
- package/dist/opencode/v1-language.js +64 -0
- package/dist/opencode/v1-module.d.ts +23 -0
- package/dist/opencode/v1-module.js +74 -0
- package/dist/opencode/v1-session-auth.d.ts +5 -0
- package/dist/opencode/v1-session-auth.js +98 -0
- package/dist/providers/claude/adapter.d.ts +7 -0
- package/dist/providers/claude/adapter.js +37 -0
- package/dist/providers/claude/atomic-private-file.d.ts +13 -0
- package/dist/providers/claude/atomic-private-file.js +94 -0
- package/dist/providers/claude/auth-json.d.ts +2 -0
- package/dist/providers/claude/auth-json.js +14 -0
- package/dist/providers/claude/auth.d.ts +24 -0
- package/dist/providers/claude/auth.js +200 -0
- package/dist/providers/claude/cli-version.d.ts +10 -0
- package/dist/providers/claude/cli-version.js +36 -0
- package/dist/providers/claude/compat-betas.d.ts +5 -0
- package/dist/providers/claude/compat-betas.js +54 -0
- package/dist/providers/claude/compat-config.d.ts +8 -0
- package/dist/providers/claude/compat-config.js +31 -0
- package/dist/providers/claude/compat-request.d.ts +12 -0
- package/dist/providers/claude/compat-request.js +151 -0
- package/dist/providers/claude/compat-response.d.ts +1 -0
- package/dist/providers/claude/compat-response.js +54 -0
- package/dist/providers/claude/compat-signing.d.ts +9 -0
- package/dist/providers/claude/compat-signing.js +24 -0
- package/dist/providers/claude/compat-transform.d.ts +3 -0
- package/dist/providers/claude/compat-transform.js +224 -0
- package/dist/providers/claude/credentials.d.ts +7 -0
- package/dist/providers/claude/credentials.js +37 -0
- package/dist/providers/claude/emit-stream.d.ts +2 -0
- package/dist/providers/claude/emit-stream.js +62 -0
- package/dist/providers/claude/keychain-account.d.ts +1 -0
- package/dist/providers/claude/keychain-account.js +14 -0
- package/dist/providers/claude/language-model.d.ts +8 -0
- package/dist/providers/claude/language-model.js +109 -0
- package/dist/providers/claude/models.d.ts +9 -0
- package/dist/providers/claude/models.js +24 -0
- package/dist/providers/claude/prompt.d.ts +42 -0
- package/dist/providers/claude/prompt.js +134 -0
- package/dist/providers/claude/refresh.d.ts +19 -0
- package/dist/providers/claude/refresh.js +85 -0
- package/dist/providers/claude/sse-convert.d.ts +6 -0
- package/dist/providers/claude/sse-convert.js +74 -0
- package/dist/providers/claude/sse.d.ts +71 -0
- package/dist/providers/claude/sse.js +123 -0
- package/dist/providers/claude/transform.d.ts +32 -0
- package/dist/providers/claude/transform.js +52 -0
- package/dist/providers/claude/writeback.d.ts +18 -0
- package/dist/providers/claude/writeback.js +140 -0
- package/dist/providers/command-code/adapter.d.ts +7 -0
- package/dist/providers/command-code/adapter.js +37 -0
- package/dist/providers/command-code/auth.d.ts +5 -0
- package/dist/providers/command-code/auth.js +88 -0
- package/dist/providers/command-code/cli-version.d.ts +10 -0
- package/dist/providers/command-code/cli-version.js +36 -0
- package/dist/providers/command-code/emit-stream.d.ts +2 -0
- package/dist/providers/command-code/emit-stream.js +226 -0
- package/dist/providers/command-code/errors.d.ts +33 -0
- package/dist/providers/command-code/errors.js +105 -0
- package/dist/providers/command-code/language-model.d.ts +15 -0
- package/dist/providers/command-code/language-model.js +203 -0
- package/dist/providers/command-code/models.d.ts +3 -0
- package/dist/providers/command-code/models.js +18 -0
- package/dist/providers/command-code/record-stream.d.ts +1 -0
- package/dist/providers/command-code/record-stream.js +61 -0
- package/dist/providers/command-code/request-lifecycle.d.ts +8 -0
- package/dist/providers/command-code/request-lifecycle.js +33 -0
- package/dist/providers/command-code/request.d.ts +14 -0
- package/dist/providers/command-code/request.js +167 -0
- package/dist/providers/command-code/session.d.ts +5 -0
- package/dist/providers/command-code/session.js +9 -0
- package/dist/providers/cursor/adapter.d.ts +7 -0
- package/dist/providers/cursor/adapter.js +37 -0
- package/dist/providers/cursor/auth.d.ts +6 -0
- package/dist/providers/cursor/auth.js +56 -0
- package/dist/providers/cursor/blob-store.d.ts +26 -0
- package/dist/providers/cursor/blob-store.js +119 -0
- package/dist/providers/cursor/bridge-client.d.ts +33 -0
- package/dist/providers/cursor/bridge-client.js +200 -0
- package/dist/providers/cursor/bridge-event-sanitize.d.ts +3 -0
- package/dist/providers/cursor/bridge-event-sanitize.js +49 -0
- package/dist/providers/cursor/bridge-limits.d.ts +3 -0
- package/dist/providers/cursor/bridge-limits.js +10 -0
- package/dist/providers/cursor/bridge-process.d.ts +45 -0
- package/dist/providers/cursor/bridge-process.js +211 -0
- package/dist/providers/cursor/bridge-protocol.d.ts +68 -0
- package/dist/providers/cursor/bridge-protocol.js +49 -0
- package/dist/providers/cursor/bridge-serialize.d.ts +3 -0
- package/dist/providers/cursor/bridge-serialize.js +53 -0
- package/dist/providers/cursor/bridge-wire.d.ts +3 -0
- package/dist/providers/cursor/bridge-wire.js +163 -0
- package/dist/providers/cursor/checkpoint-store.d.ts +28 -0
- package/dist/providers/cursor/checkpoint-store.js +94 -0
- package/dist/providers/cursor/connect-frame-stream.d.ts +19 -0
- package/dist/providers/cursor/connect-frame-stream.js +160 -0
- package/dist/providers/cursor/connect-frame.d.ts +31 -0
- package/dist/providers/cursor/connect-frame.js +121 -0
- package/dist/providers/cursor/credentials.d.ts +5 -0
- package/dist/providers/cursor/credentials.js +22 -0
- package/dist/providers/cursor/direct-run-types.d.ts +33 -0
- package/dist/providers/cursor/direct-run-types.js +1 -0
- package/dist/providers/cursor/direct-run.d.ts +5 -0
- package/dist/providers/cursor/direct-run.js +213 -0
- package/dist/providers/cursor/direct-runtime.d.ts +23 -0
- package/dist/providers/cursor/direct-runtime.js +111 -0
- package/dist/providers/cursor/direct-stream.d.ts +28 -0
- package/dist/providers/cursor/direct-stream.js +190 -0
- package/dist/providers/cursor/exec-reply.d.ts +13 -0
- package/dist/providers/cursor/exec-reply.js +102 -0
- package/dist/providers/cursor/h2-bridge-response.d.ts +9 -0
- package/dist/providers/cursor/h2-bridge-response.js +51 -0
- package/dist/providers/cursor/h2-bridge-session.d.ts +24 -0
- package/dist/providers/cursor/h2-bridge-session.js +197 -0
- package/dist/providers/cursor/h2-bridge.d.ts +2 -0
- package/dist/providers/cursor/h2-bridge.js +12865 -0
- package/dist/providers/cursor/http2.d.ts +18 -0
- package/dist/providers/cursor/http2.js +144 -0
- package/dist/providers/cursor/interaction-reply.d.ts +6 -0
- package/dist/providers/cursor/interaction-reply.js +52 -0
- package/dist/providers/cursor/language-generate.d.ts +2 -0
- package/dist/providers/cursor/language-generate.js +35 -0
- package/dist/providers/cursor/language-model.d.ts +13 -0
- package/dist/providers/cursor/language-model.js +77 -0
- package/dist/providers/cursor/legacy-stream.d.ts +11 -0
- package/dist/providers/cursor/legacy-stream.js +115 -0
- package/dist/providers/cursor/mcp-tools.d.ts +7 -0
- package/dist/providers/cursor/mcp-tools.js +15 -0
- package/dist/providers/cursor/models.d.ts +14 -0
- package/dist/providers/cursor/models.js +116 -0
- package/dist/providers/cursor/ndjson.d.ts +3 -0
- package/dist/providers/cursor/ndjson.js +100 -0
- package/dist/providers/cursor/prompt.d.ts +4 -0
- package/dist/providers/cursor/prompt.js +142 -0
- package/dist/providers/cursor/proto/checkpoint.d.ts +35 -0
- package/dist/providers/cursor/proto/checkpoint.js +114 -0
- package/dist/providers/cursor/proto/context.d.ts +64 -0
- package/dist/providers/cursor/proto/context.js +178 -0
- package/dist/providers/cursor/proto/errors.d.ts +16 -0
- package/dist/providers/cursor/proto/errors.js +26 -0
- package/dist/providers/cursor/proto/exec-control.d.ts +20 -0
- package/dist/providers/cursor/proto/exec-control.js +54 -0
- package/dist/providers/cursor/proto/exec.d.ts +47 -0
- package/dist/providers/cursor/proto/exec.js +154 -0
- package/dist/providers/cursor/proto/fields.d.ts +22 -0
- package/dist/providers/cursor/proto/fields.js +97 -0
- package/dist/providers/cursor/proto/interaction-query.d.ts +15 -0
- package/dist/providers/cursor/proto/interaction-query.js +79 -0
- package/dist/providers/cursor/proto/interaction-tool-update.d.ts +10 -0
- package/dist/providers/cursor/proto/interaction-tool-update.js +58 -0
- package/dist/providers/cursor/proto/interaction-turn-ended.d.ts +6 -0
- package/dist/providers/cursor/proto/interaction-turn-ended.js +18 -0
- package/dist/providers/cursor/proto/interaction.d.ts +65 -0
- package/dist/providers/cursor/proto/interaction.js +185 -0
- package/dist/providers/cursor/proto/kv.d.ts +25 -0
- package/dist/providers/cursor/proto/kv.js +109 -0
- package/dist/providers/cursor/proto/mcp-result.d.ts +40 -0
- package/dist/providers/cursor/proto/mcp-result.js +150 -0
- package/dist/providers/cursor/proto/mcp.d.ts +19 -0
- package/dist/providers/cursor/proto/mcp.js +78 -0
- package/dist/providers/cursor/proto/model.d.ts +11 -0
- package/dist/providers/cursor/proto/model.js +36 -0
- package/dist/providers/cursor/proto/output-location.d.ts +7 -0
- package/dist/providers/cursor/proto/output-location.js +53 -0
- package/dist/providers/cursor/proto/prewarm.d.ts +16 -0
- package/dist/providers/cursor/proto/prewarm.js +68 -0
- package/dist/providers/cursor/proto/request-context.d.ts +16 -0
- package/dist/providers/cursor/proto/request-context.js +58 -0
- package/dist/providers/cursor/proto/request.d.ts +44 -0
- package/dist/providers/cursor/proto/request.js +111 -0
- package/dist/providers/cursor/proto/run-request.d.ts +19 -0
- package/dist/providers/cursor/proto/run-request.js +68 -0
- package/dist/providers/cursor/proto/server.d.ts +35 -0
- package/dist/providers/cursor/proto/server.js +93 -0
- package/dist/providers/cursor/proto/unknown-field.d.ts +1 -0
- package/dist/providers/cursor/proto/unknown-field.js +22 -0
- package/dist/providers/cursor/proto-value.d.ts +3 -0
- package/dist/providers/cursor/proto-value.js +170 -0
- package/dist/providers/cursor/proto-wire.d.ts +22 -0
- package/dist/providers/cursor/proto-wire.js +224 -0
- package/dist/providers/cursor/protocol-failure.d.ts +18 -0
- package/dist/providers/cursor/protocol-failure.js +45 -0
- package/dist/providers/cursor/recovery.d.ts +48 -0
- package/dist/providers/cursor/recovery.js +102 -0
- package/dist/providers/cursor/request-blob-ownership.d.ts +15 -0
- package/dist/providers/cursor/request-blob-ownership.js +39 -0
- package/dist/providers/cursor/request-build.d.ts +18 -0
- package/dist/providers/cursor/request-build.js +123 -0
- package/dist/providers/cursor/request-history.d.ts +32 -0
- package/dist/providers/cursor/request-history.js +163 -0
- package/dist/providers/cursor/request-input.d.ts +75 -0
- package/dist/providers/cursor/request-input.js +123 -0
- package/dist/providers/cursor/run-events.d.ts +15 -0
- package/dist/providers/cursor/run-events.js +43 -0
- package/dist/providers/cursor/run-session-expiry.d.ts +15 -0
- package/dist/providers/cursor/run-session-expiry.js +21 -0
- package/dist/providers/cursor/run-session.d.ts +50 -0
- package/dist/providers/cursor/run-session.js +205 -0
- package/dist/providers/cursor/run.d.ts +9 -0
- package/dist/providers/cursor/run.js +151 -0
- package/dist/providers/cursor/runner.d.ts +1 -0
- package/dist/providers/cursor/runner.js +55 -0
- package/dist/providers/cursor/server-dispatch-types.d.ts +83 -0
- package/dist/providers/cursor/server-dispatch-types.js +1 -0
- package/dist/providers/cursor/server-dispatch.d.ts +3 -0
- package/dist/providers/cursor/server-dispatch.js +178 -0
- package/dist/providers/cursor/session-state.d.ts +21 -0
- package/dist/providers/cursor/session-state.js +118 -0
- package/dist/providers/cursor/session.d.ts +1 -0
- package/dist/providers/cursor/session.js +26 -0
- package/dist/providers/cursor/settle-cleanup.d.ts +1 -0
- package/dist/providers/cursor/settle-cleanup.js +11 -0
- package/dist/providers/cursor/stream-adapter.d.ts +17 -0
- package/dist/providers/cursor/stream-adapter.js +99 -0
- package/dist/providers/cursor/tool-continuation.d.ts +14 -0
- package/dist/providers/cursor/tool-continuation.js +134 -0
- package/dist/providers/cursor/tool-stream.d.ts +2 -0
- package/dist/providers/cursor/tool-stream.js +220 -0
- package/dist/providers/cursor/usage.d.ts +3 -0
- package/dist/providers/cursor/usage.js +35 -0
- package/dist/providers/ollama/adapter.d.ts +8 -0
- package/dist/providers/ollama/adapter.js +65 -0
- package/dist/providers/ollama/catalog-state.d.ts +17 -0
- package/dist/providers/ollama/catalog-state.js +40 -0
- package/dist/providers/ollama/cloud-catalog.d.ts +3 -0
- package/dist/providers/ollama/cloud-catalog.js +82 -0
- package/dist/providers/ollama/errors.d.ts +14 -0
- package/dist/providers/ollama/errors.js +19 -0
- package/dist/providers/ollama/generate.d.ts +2 -0
- package/dist/providers/ollama/generate.js +49 -0
- package/dist/providers/ollama/html-links.d.ts +1 -0
- package/dist/providers/ollama/html-links.js +30 -0
- package/dist/providers/ollama/http.d.ts +12 -0
- package/dist/providers/ollama/http.js +67 -0
- package/dist/providers/ollama/index.d.ts +8 -0
- package/dist/providers/ollama/index.js +8 -0
- package/dist/providers/ollama/language-model.d.ts +11 -0
- package/dist/providers/ollama/language-model.js +62 -0
- package/dist/providers/ollama/local-catalog.d.ts +3 -0
- package/dist/providers/ollama/local-catalog.js +38 -0
- package/dist/providers/ollama/ndjson.d.ts +3 -0
- package/dist/providers/ollama/ndjson.js +51 -0
- package/dist/providers/ollama/prompt.d.ts +8 -0
- package/dist/providers/ollama/prompt.js +141 -0
- package/dist/providers/ollama/protocol.d.ts +56 -0
- package/dist/providers/ollama/protocol.js +26 -0
- package/dist/providers/ollama/runtime.d.ts +11 -0
- package/dist/providers/ollama/runtime.js +128 -0
- package/dist/providers/ollama/stream.d.ts +8 -0
- package/dist/providers/ollama/stream.js +110 -0
- package/dist/sdk/command-code.d.ts +5 -0
- package/dist/sdk/command-code.js +6 -0
- package/dist/sdk/cursor.d.ts +5 -0
- package/dist/sdk/cursor.js +6 -0
- package/dist/sdk/ollama.d.ts +5 -0
- package/dist/sdk/ollama.js +6 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +94 -0
- package/docs/README.ko.md +189 -0
- package/package.json +75 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Derived from Nomadcxx/opencode-cursor@8e14a26c1e080382f471a729436092ef72edf34e.
|
|
2
|
+
// Licensed under BSD-3-Clause. See THIRD_PARTY_NOTICES.md.
|
|
3
|
+
const TOOL_ALIASES = {
|
|
4
|
+
runcommand: "bash",
|
|
5
|
+
executecommand: "bash",
|
|
6
|
+
runterminalcommand: "bash",
|
|
7
|
+
terminalcommand: "bash",
|
|
8
|
+
shellcommand: "bash",
|
|
9
|
+
shell: "bash",
|
|
10
|
+
terminal: "bash",
|
|
11
|
+
bashcommand: "bash",
|
|
12
|
+
runbash: "bash",
|
|
13
|
+
executebash: "bash",
|
|
14
|
+
strreplace: "edit",
|
|
15
|
+
writefile: "write",
|
|
16
|
+
findfiles: "glob",
|
|
17
|
+
searchfiles: "glob",
|
|
18
|
+
globfiles: "glob",
|
|
19
|
+
fileglob: "glob",
|
|
20
|
+
matchfiles: "glob",
|
|
21
|
+
createdirectory: "mkdir",
|
|
22
|
+
makedirectory: "mkdir",
|
|
23
|
+
mkdirp: "mkdir",
|
|
24
|
+
createdir: "mkdir",
|
|
25
|
+
makefolder: "mkdir",
|
|
26
|
+
delete: "rm",
|
|
27
|
+
deletefile: "rm",
|
|
28
|
+
deletepath: "rm",
|
|
29
|
+
deletedirectory: "rm",
|
|
30
|
+
remove: "rm",
|
|
31
|
+
removefile: "rm",
|
|
32
|
+
removepath: "rm",
|
|
33
|
+
unlink: "rm",
|
|
34
|
+
rmdir: "rm",
|
|
35
|
+
getfileinfo: "stat",
|
|
36
|
+
fileinfo: "stat",
|
|
37
|
+
filestat: "stat",
|
|
38
|
+
pathinfo: "stat",
|
|
39
|
+
listdirectory: "ls",
|
|
40
|
+
listfiles: "ls",
|
|
41
|
+
listdir: "ls",
|
|
42
|
+
readdir: "ls",
|
|
43
|
+
updatetodos: "todowrite",
|
|
44
|
+
updatetodostoolcall: "todowrite",
|
|
45
|
+
todowritetoolcall: "todowrite",
|
|
46
|
+
writetodos: "todowrite",
|
|
47
|
+
todowritefn: "todowrite",
|
|
48
|
+
readtodos: "todoread",
|
|
49
|
+
readtodostoolcall: "todoread",
|
|
50
|
+
todoreadtoolcall: "todoread",
|
|
51
|
+
callomoagent: "call_omo_agent",
|
|
52
|
+
callagent: "call_omo_agent",
|
|
53
|
+
invokeagent: "call_omo_agent",
|
|
54
|
+
delegatetask: "task",
|
|
55
|
+
delegate: "task",
|
|
56
|
+
runtask: "task",
|
|
57
|
+
subagent: "task",
|
|
58
|
+
useskill: "skill",
|
|
59
|
+
invokeskill: "skill",
|
|
60
|
+
runskill: "skill",
|
|
61
|
+
skillmcp: "skill_mcp",
|
|
62
|
+
runmcpskill: "skill_mcp",
|
|
63
|
+
invokeskillmcp: "skill_mcp",
|
|
64
|
+
askquestion: "question",
|
|
65
|
+
askuser: "question",
|
|
66
|
+
askuserquestion: "question",
|
|
67
|
+
askquestions: "question",
|
|
68
|
+
promptuser: "question",
|
|
69
|
+
};
|
|
70
|
+
const ARGUMENT_ALIASES = {
|
|
71
|
+
filepath: "path",
|
|
72
|
+
filename: "path",
|
|
73
|
+
file: "path",
|
|
74
|
+
targetpath: "path",
|
|
75
|
+
directorypath: "path",
|
|
76
|
+
dir: "path",
|
|
77
|
+
folder: "path",
|
|
78
|
+
directory: "path",
|
|
79
|
+
targetdirectory: "path",
|
|
80
|
+
targetfile: "path",
|
|
81
|
+
globpattern: "pattern",
|
|
82
|
+
filepattern: "pattern",
|
|
83
|
+
searchpattern: "pattern",
|
|
84
|
+
includepattern: "include",
|
|
85
|
+
workingdirectory: "cwd",
|
|
86
|
+
workdir: "cwd",
|
|
87
|
+
currentdirectory: "cwd",
|
|
88
|
+
cmd: "command",
|
|
89
|
+
script: "command",
|
|
90
|
+
shellcommand: "command",
|
|
91
|
+
terminalcommand: "command",
|
|
92
|
+
contents: "content",
|
|
93
|
+
text: "content",
|
|
94
|
+
body: "content",
|
|
95
|
+
data: "content",
|
|
96
|
+
payload: "content",
|
|
97
|
+
streamcontent: "content",
|
|
98
|
+
recursive: "force",
|
|
99
|
+
oldstring: "old_string",
|
|
100
|
+
newstring: "new_string",
|
|
101
|
+
subagenttype: "subagent_type",
|
|
102
|
+
};
|
|
103
|
+
function stringField(value, key) {
|
|
104
|
+
if (!(key in value)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const field = Reflect.get(value, key);
|
|
108
|
+
return typeof field === "string" && field.length > 0 ? field : null;
|
|
109
|
+
}
|
|
110
|
+
function toolNameFromKey(key) {
|
|
111
|
+
return key.endsWith("ToolCall") ? key.slice(0, -"ToolCall".length) : key;
|
|
112
|
+
}
|
|
113
|
+
function normalizeToolName(name) {
|
|
114
|
+
return name.toLowerCase().replaceAll(/[^a-z0-9]/g, "");
|
|
115
|
+
}
|
|
116
|
+
function resolveToolName(name, allowed) {
|
|
117
|
+
if (allowed.has(name)) {
|
|
118
|
+
return name;
|
|
119
|
+
}
|
|
120
|
+
const normalized = normalizeToolName(name);
|
|
121
|
+
const alias = normalizeToolName(TOOL_ALIASES[normalized] ?? normalized);
|
|
122
|
+
for (const candidate of allowed.keys()) {
|
|
123
|
+
const normalizedCandidate = normalizeToolName(candidate);
|
|
124
|
+
if (normalizedCandidate === normalized ||
|
|
125
|
+
normalizedCandidate === alias ||
|
|
126
|
+
normalizedCandidate === normalizeToolName(`oc_${alias}`)) {
|
|
127
|
+
return candidate;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
function objectRecord(value) {
|
|
133
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const result = {};
|
|
137
|
+
for (const key of Object.keys(value)) {
|
|
138
|
+
result[key] = Reflect.get(value, key);
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
function normalizeArguments(args, schema) {
|
|
143
|
+
const input = objectRecord(args);
|
|
144
|
+
const schemaRecord = objectRecord(schema);
|
|
145
|
+
const properties = objectRecord(schemaRecord?.["properties"]);
|
|
146
|
+
if (input === null || properties === null) {
|
|
147
|
+
return args;
|
|
148
|
+
}
|
|
149
|
+
const propertyByNormalized = new Map();
|
|
150
|
+
for (const property of Object.keys(properties)) {
|
|
151
|
+
const normalizedProperty = normalizeToolName(property);
|
|
152
|
+
propertyByNormalized.set(ARGUMENT_ALIASES[normalizedProperty] ?? normalizedProperty, property);
|
|
153
|
+
}
|
|
154
|
+
const normalized = {};
|
|
155
|
+
for (const [key, value] of Object.entries(input)) {
|
|
156
|
+
const normalizedKey = normalizeToolName(key);
|
|
157
|
+
const alias = ARGUMENT_ALIASES[normalizedKey] ?? normalizedKey;
|
|
158
|
+
const target = (key in properties ? key : undefined) ?? propertyByNormalized.get(alias) ?? key;
|
|
159
|
+
if (!(target in normalized)) {
|
|
160
|
+
normalized[target] = value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (schemaRecord?.["additionalProperties"] === false) {
|
|
164
|
+
for (const key of Object.keys(normalized)) {
|
|
165
|
+
if (!(key in properties)) {
|
|
166
|
+
delete normalized[key];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return normalized;
|
|
171
|
+
}
|
|
172
|
+
function nestedToolCall(value) {
|
|
173
|
+
if (!("tool_call" in value)) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const payload = Reflect.get(value, "tool_call");
|
|
177
|
+
if (typeof payload !== "object" || payload === null) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
const entries = Object.entries(payload);
|
|
181
|
+
const first = entries.at(0);
|
|
182
|
+
if (first === undefined) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const [key, nested] = first;
|
|
186
|
+
if (typeof nested !== "object" || nested === null) {
|
|
187
|
+
return { name: toolNameFromKey(key), args: {} };
|
|
188
|
+
}
|
|
189
|
+
const args = "args" in nested ? Reflect.get(nested, "args") : nested;
|
|
190
|
+
return { name: toolNameFromKey(key), args };
|
|
191
|
+
}
|
|
192
|
+
export function cursorToolParts(parsed, allowedTools) {
|
|
193
|
+
const type = stringField(parsed, "type");
|
|
194
|
+
if (type !== "tool_call") {
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
const subtype = stringField(parsed, "subtype") ?? "started";
|
|
198
|
+
const id = stringField(parsed, "call_id") ?? stringField(parsed, "id") ?? "tool-1";
|
|
199
|
+
const flatName = stringField(parsed, "name") ?? stringField(parsed, "toolName");
|
|
200
|
+
const nested = nestedToolCall(parsed);
|
|
201
|
+
const rawToolName = flatName ?? nested?.name ?? "unknown";
|
|
202
|
+
const toolName = resolveToolName(rawToolName, allowedTools);
|
|
203
|
+
const args = "arguments" in parsed ? Reflect.get(parsed, "arguments") : nested?.args;
|
|
204
|
+
if (toolName === null) {
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
const input = JSON.stringify(normalizeArguments(args ?? {}, allowedTools.get(toolName)));
|
|
208
|
+
if (subtype === "delta") {
|
|
209
|
+
return [{ type: "tool-input-delta", id, delta: input }];
|
|
210
|
+
}
|
|
211
|
+
if (subtype === "completed") {
|
|
212
|
+
return [{ type: "tool-input-end", id }];
|
|
213
|
+
}
|
|
214
|
+
return [
|
|
215
|
+
{ type: "tool-input-start", id, toolName },
|
|
216
|
+
{ type: "tool-input-delta", id, delta: input },
|
|
217
|
+
{ type: "tool-input-end", id },
|
|
218
|
+
{ type: "tool-call", toolCallId: id, toolName, input, providerExecuted: false },
|
|
219
|
+
];
|
|
220
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function emptyCursorUsage() {
|
|
2
|
+
return {
|
|
3
|
+
inputTokens: {
|
|
4
|
+
total: undefined,
|
|
5
|
+
noCache: undefined,
|
|
6
|
+
cacheRead: undefined,
|
|
7
|
+
cacheWrite: undefined,
|
|
8
|
+
},
|
|
9
|
+
outputTokens: { total: undefined, text: undefined, reasoning: undefined },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function cursorUsage(value) {
|
|
13
|
+
if (!("usage" in value)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const rawUsage = value.usage;
|
|
17
|
+
if (typeof rawUsage !== "object" || rawUsage === null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const numberField = (key) => {
|
|
21
|
+
const field = Reflect.get(rawUsage, key);
|
|
22
|
+
return typeof field === "number" ? field : undefined;
|
|
23
|
+
};
|
|
24
|
+
const input = numberField("inputTokens");
|
|
25
|
+
const output = numberField("outputTokens");
|
|
26
|
+
return {
|
|
27
|
+
inputTokens: {
|
|
28
|
+
total: input,
|
|
29
|
+
noCache: input,
|
|
30
|
+
cacheRead: numberField("cacheReadTokens"),
|
|
31
|
+
cacheWrite: numberField("cacheWriteTokens"),
|
|
32
|
+
},
|
|
33
|
+
outputTokens: { total: output, text: output, reasoning: undefined },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProviderAdapter } from "../../core/adapter";
|
|
2
|
+
import type { OllamaCatalogState } from "./catalog-state";
|
|
3
|
+
import type { OllamaFetch } from "./http";
|
|
4
|
+
export type OllamaAdapterOptions = {
|
|
5
|
+
readonly fetch: OllamaFetch;
|
|
6
|
+
readonly catalog: OllamaCatalogState;
|
|
7
|
+
};
|
|
8
|
+
export declare function createOllamaAdapter(options: OllamaAdapterOptions): ProviderAdapter;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { OperationCancelledError } from "../../core/errors";
|
|
2
|
+
import { parseProviderId } from "../../core/ids";
|
|
3
|
+
import { createAsyncDisposable } from "../../core/lifecycle";
|
|
4
|
+
import { OllamaCatalogError } from "./errors";
|
|
5
|
+
import { listLocalOllamaModels } from "./local-catalog";
|
|
6
|
+
function mergeModels(local, cloud) {
|
|
7
|
+
const ids = new Set();
|
|
8
|
+
const merged = [];
|
|
9
|
+
for (const model of [...local, ...cloud]) {
|
|
10
|
+
if (ids.has(model.id))
|
|
11
|
+
continue;
|
|
12
|
+
ids.add(model.id);
|
|
13
|
+
merged.push(model);
|
|
14
|
+
}
|
|
15
|
+
return merged;
|
|
16
|
+
}
|
|
17
|
+
function catalogFailure(error) {
|
|
18
|
+
if (error instanceof OperationCancelledError)
|
|
19
|
+
throw error;
|
|
20
|
+
if (error instanceof OllamaCatalogError)
|
|
21
|
+
return error;
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
export function createOllamaAdapter(options) {
|
|
25
|
+
const providerId = parseProviderId("ollama");
|
|
26
|
+
const lease = options.catalog.acquire();
|
|
27
|
+
const disposal = createAsyncDisposable(() => lease.dispose());
|
|
28
|
+
let lastMergedModels = null;
|
|
29
|
+
return {
|
|
30
|
+
providerId,
|
|
31
|
+
snapshot: async (signal) => {
|
|
32
|
+
if (signal.aborted)
|
|
33
|
+
throw new OperationCancelledError("ollama-snapshot");
|
|
34
|
+
let local;
|
|
35
|
+
try {
|
|
36
|
+
local = await listLocalOllamaModels(options.fetch, signal);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const failure = catalogFailure(error);
|
|
40
|
+
return lastMergedModels === null
|
|
41
|
+
? { status: "unavailable", providerId, reason: failure.kind }
|
|
42
|
+
: { status: "stale", providerId, models: lastMergedModels, reason: failure.kind };
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const models = mergeModels(local, await lease.refresh(signal));
|
|
46
|
+
lastMergedModels = models;
|
|
47
|
+
return { status: "ready", providerId, models };
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const failure = catalogFailure(error);
|
|
51
|
+
const previousCloud = lease.models();
|
|
52
|
+
if (previousCloud.length === 0) {
|
|
53
|
+
return lastMergedModels === null
|
|
54
|
+
? { status: "unavailable", providerId, reason: failure.kind }
|
|
55
|
+
: { status: "stale", providerId, models: lastMergedModels, reason: failure.kind };
|
|
56
|
+
}
|
|
57
|
+
const models = mergeModels(local, previousCloud);
|
|
58
|
+
lastMergedModels = models;
|
|
59
|
+
return { status: "stale", providerId, models, reason: failure.kind };
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
dispose: disposal.dispose,
|
|
63
|
+
[Symbol.asyncDispose]: disposal[Symbol.asyncDispose],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AsyncDisposableHandle } from "../../core/lifecycle";
|
|
2
|
+
import type { AdapterModel } from "../../core/models";
|
|
3
|
+
import { type OllamaFetch } from "./http";
|
|
4
|
+
export interface OllamaCatalogLease extends AsyncDisposableHandle {
|
|
5
|
+
refresh(signal: AbortSignal): Promise<readonly AdapterModel[]>;
|
|
6
|
+
models(): readonly AdapterModel[];
|
|
7
|
+
}
|
|
8
|
+
export interface OllamaCatalogState {
|
|
9
|
+
acquire(): OllamaCatalogLease;
|
|
10
|
+
activeLeaseCount(): number;
|
|
11
|
+
authorizesCloudPull(modelId: string): boolean;
|
|
12
|
+
}
|
|
13
|
+
export type OllamaCatalogStateOptions = {
|
|
14
|
+
readonly fetch?: OllamaFetch;
|
|
15
|
+
readonly familyConcurrency?: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function createOllamaCatalogState(options?: OllamaCatalogStateOptions): OllamaCatalogState;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ResourceDisposedError } from "../../core/errors";
|
|
2
|
+
import { createAsyncDisposable } from "../../core/lifecycle";
|
|
3
|
+
import { discoverOllamaCloudModels } from "./cloud-catalog";
|
|
4
|
+
import { productionOllamaFetch } from "./http";
|
|
5
|
+
export function createOllamaCatalogState(options = {}) {
|
|
6
|
+
const fetch = options.fetch ?? productionOllamaFetch;
|
|
7
|
+
const concurrency = options.familyConcurrency ?? 4;
|
|
8
|
+
let completeModels = null;
|
|
9
|
+
let authorizedIds = new Set();
|
|
10
|
+
let activeLeases = 0;
|
|
11
|
+
return {
|
|
12
|
+
acquire: () => {
|
|
13
|
+
activeLeases += 1;
|
|
14
|
+
let released = false;
|
|
15
|
+
const disposal = createAsyncDisposable(() => {
|
|
16
|
+
released = true;
|
|
17
|
+
activeLeases -= 1;
|
|
18
|
+
if (activeLeases === 0) {
|
|
19
|
+
completeModels = null;
|
|
20
|
+
authorizedIds = new Set();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
refresh: async (signal) => {
|
|
25
|
+
if (released)
|
|
26
|
+
throw new ResourceDisposedError("ollama-catalog-lease");
|
|
27
|
+
const discovered = await discoverOllamaCloudModels(fetch, signal, concurrency);
|
|
28
|
+
completeModels = discovered;
|
|
29
|
+
authorizedIds = new Set(discovered.map(({ id }) => id));
|
|
30
|
+
return discovered;
|
|
31
|
+
},
|
|
32
|
+
models: () => completeModels ?? [],
|
|
33
|
+
dispose: disposal.dispose,
|
|
34
|
+
[Symbol.asyncDispose]: disposal[Symbol.asyncDispose],
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
activeLeaseCount: () => activeLeases,
|
|
38
|
+
authorizesCloudPull: (modelId) => activeLeases > 0 && authorizedIds.has(modelId),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { parseAdapterModel } from "../../core/models";
|
|
3
|
+
import { OllamaCatalogError } from "./errors";
|
|
4
|
+
import { extractOfficialLibraryPaths } from "./html-links";
|
|
5
|
+
import { requestOllamaCatalog } from "./http";
|
|
6
|
+
const CLOUD_SEARCH_URL = "https://ollama.com/search?c=cloud";
|
|
7
|
+
const FAMILY_CONCURRENCY = 4;
|
|
8
|
+
const FamilySchema = z.string().regex(/^[A-Za-z0-9._-]+$/);
|
|
9
|
+
const TagSchema = z.string().min(1).max(256);
|
|
10
|
+
function searchFamilies(html) {
|
|
11
|
+
const families = [];
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
for (const path of extractOfficialLibraryPaths(html)) {
|
|
14
|
+
const match = /^\/library\/([^/:]+)$/.exec(path);
|
|
15
|
+
const parsed = FamilySchema.safeParse(match?.[1]);
|
|
16
|
+
if (parsed.success && !seen.has(parsed.data)) {
|
|
17
|
+
seen.add(parsed.data);
|
|
18
|
+
families.push(parsed.data);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (families.length === 0)
|
|
22
|
+
throw new OllamaCatalogError("cloud-search", "invalid-data");
|
|
23
|
+
return families;
|
|
24
|
+
}
|
|
25
|
+
function familyModels(family, html) {
|
|
26
|
+
const models = [];
|
|
27
|
+
const seen = new Set();
|
|
28
|
+
for (const path of extractOfficialLibraryPaths(html)) {
|
|
29
|
+
const match = /^\/library\/([^/:]+):([^/]+)$/.exec(path);
|
|
30
|
+
if (match?.[1] !== family)
|
|
31
|
+
continue;
|
|
32
|
+
const tag = TagSchema.safeParse(match[2]);
|
|
33
|
+
if (!tag.success || (tag.data !== "cloud" && !tag.data.endsWith("-cloud")))
|
|
34
|
+
continue;
|
|
35
|
+
const id = `${family}:${tag.data}`;
|
|
36
|
+
if (!seen.has(id)) {
|
|
37
|
+
seen.add(id);
|
|
38
|
+
models.push(parseAdapterModel({ id }));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (models.length === 0)
|
|
42
|
+
throw new OllamaCatalogError("cloud-family", "invalid-data");
|
|
43
|
+
return models;
|
|
44
|
+
}
|
|
45
|
+
async function discoverFamily(family, fetch, signal) {
|
|
46
|
+
const html = await requestOllamaCatalog({
|
|
47
|
+
url: `https://ollama.com/library/${family}`,
|
|
48
|
+
accept: "text/html",
|
|
49
|
+
operation: "cloud-family",
|
|
50
|
+
fetch,
|
|
51
|
+
signal,
|
|
52
|
+
});
|
|
53
|
+
return familyModels(family, html);
|
|
54
|
+
}
|
|
55
|
+
export async function discoverOllamaCloudModels(fetch, signal, concurrency = FAMILY_CONCURRENCY) {
|
|
56
|
+
const workerCount = z.number().int().min(1).max(8).parse(concurrency);
|
|
57
|
+
const searchHtml = await requestOllamaCatalog({
|
|
58
|
+
url: CLOUD_SEARCH_URL,
|
|
59
|
+
accept: "text/html",
|
|
60
|
+
operation: "cloud-search",
|
|
61
|
+
fetch,
|
|
62
|
+
signal,
|
|
63
|
+
});
|
|
64
|
+
const families = searchFamilies(searchHtml);
|
|
65
|
+
const results = Array.from({ length: families.length }, () => []);
|
|
66
|
+
let nextFamily = 0;
|
|
67
|
+
const worker = async () => {
|
|
68
|
+
while (nextFamily < families.length) {
|
|
69
|
+
const index = nextFamily;
|
|
70
|
+
nextFamily += 1;
|
|
71
|
+
const family = families[index];
|
|
72
|
+
if (family === undefined)
|
|
73
|
+
return;
|
|
74
|
+
results[index] = await discoverFamily(family, fetch, signal);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
await Promise.all(Array.from({ length: Math.min(workerCount, families.length) }, worker));
|
|
78
|
+
const models = results.flat();
|
|
79
|
+
if (models.length === 0)
|
|
80
|
+
throw new OllamaCatalogError("cloud-search", "invalid-data");
|
|
81
|
+
return models;
|
|
82
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type OllamaCatalogErrorKind = "invalid-data" | "transport-error";
|
|
2
|
+
export declare class OllamaCatalogError extends Error {
|
|
3
|
+
readonly operation: "cloud-family" | "cloud-search" | "local-tags";
|
|
4
|
+
readonly kind: OllamaCatalogErrorKind;
|
|
5
|
+
readonly name = "OllamaCatalogError";
|
|
6
|
+
constructor(operation: "cloud-family" | "cloud-search" | "local-tags", kind: OllamaCatalogErrorKind);
|
|
7
|
+
}
|
|
8
|
+
export type OllamaGenerationOperation = "chat" | "chat-response" | "model-unavailable" | "prompt" | "pull" | "pull-response" | "tags";
|
|
9
|
+
export declare class OllamaGenerationError extends Error {
|
|
10
|
+
readonly operation: OllamaGenerationOperation;
|
|
11
|
+
readonly name = "OllamaGenerationError";
|
|
12
|
+
readonly code = "OLLAMA_GENERATION_ERROR";
|
|
13
|
+
constructor(operation: OllamaGenerationOperation);
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class OllamaCatalogError extends Error {
|
|
2
|
+
operation;
|
|
3
|
+
kind;
|
|
4
|
+
name = "OllamaCatalogError";
|
|
5
|
+
constructor(operation, kind) {
|
|
6
|
+
super("Ollama catalog request failed");
|
|
7
|
+
this.operation = operation;
|
|
8
|
+
this.kind = kind;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class OllamaGenerationError extends Error {
|
|
12
|
+
operation;
|
|
13
|
+
name = "OllamaGenerationError";
|
|
14
|
+
code = "OLLAMA_GENERATION_ERROR";
|
|
15
|
+
constructor(operation) {
|
|
16
|
+
super("Ollama generation failed");
|
|
17
|
+
this.operation = operation;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export async function generateFromOllamaStream(stream) {
|
|
2
|
+
const content = [];
|
|
3
|
+
const text = [];
|
|
4
|
+
const reasoning = [];
|
|
5
|
+
let warnings = [];
|
|
6
|
+
let finish = null;
|
|
7
|
+
const reader = stream.getReader();
|
|
8
|
+
try {
|
|
9
|
+
for (;;) {
|
|
10
|
+
const next = await reader.read();
|
|
11
|
+
if (next.done)
|
|
12
|
+
break;
|
|
13
|
+
switch (next.value.type) {
|
|
14
|
+
case "text-delta":
|
|
15
|
+
text.push(next.value.delta);
|
|
16
|
+
break;
|
|
17
|
+
case "reasoning-delta":
|
|
18
|
+
reasoning.push(next.value.delta);
|
|
19
|
+
break;
|
|
20
|
+
case "tool-call":
|
|
21
|
+
content.push(next.value);
|
|
22
|
+
break;
|
|
23
|
+
case "finish":
|
|
24
|
+
finish = next.value;
|
|
25
|
+
break;
|
|
26
|
+
case "stream-start":
|
|
27
|
+
warnings = next.value.warnings;
|
|
28
|
+
break;
|
|
29
|
+
case "error":
|
|
30
|
+
throw next.value.error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
reader.releaseLock();
|
|
36
|
+
}
|
|
37
|
+
if (finish === null)
|
|
38
|
+
throw new TypeError("Ollama stream ended without a finish part");
|
|
39
|
+
if (text.length > 0)
|
|
40
|
+
content.unshift({ type: "text", text: text.join("") });
|
|
41
|
+
if (reasoning.length > 0)
|
|
42
|
+
content.unshift({ type: "reasoning", text: reasoning.join("") });
|
|
43
|
+
return {
|
|
44
|
+
content,
|
|
45
|
+
finishReason: finish.finishReason,
|
|
46
|
+
usage: finish.usage,
|
|
47
|
+
warnings,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractOfficialLibraryPaths(html: string): readonly string[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const HtmlSchema = z.string().max(256 * 1024);
|
|
3
|
+
const HrefSchema = z.string().min(1).max(2048);
|
|
4
|
+
const ANCHOR_HREF = /<a\b[^>]*\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/giu;
|
|
5
|
+
export function extractOfficialLibraryPaths(html) {
|
|
6
|
+
const source = HtmlSchema.parse(html);
|
|
7
|
+
const paths = [];
|
|
8
|
+
for (const match of source.matchAll(ANCHOR_HREF)) {
|
|
9
|
+
const href = HrefSchema.safeParse(match[1] ?? match[2] ?? match[3]);
|
|
10
|
+
if (!href.success)
|
|
11
|
+
continue;
|
|
12
|
+
let url;
|
|
13
|
+
try {
|
|
14
|
+
url = new URL(href.data, "https://ollama.com");
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof TypeError)
|
|
18
|
+
continue;
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
if (url.origin === "https://ollama.com" &&
|
|
22
|
+
url.username === "" &&
|
|
23
|
+
url.password === "" &&
|
|
24
|
+
url.search === "" &&
|
|
25
|
+
url.hash === "") {
|
|
26
|
+
paths.push(url.pathname);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return paths;
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type OllamaFetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
export type OllamaCatalogOperation = "cloud-family" | "cloud-search" | "local-tags";
|
|
3
|
+
export declare const productionOllamaFetch: OllamaFetch;
|
|
4
|
+
type CatalogRequest = {
|
|
5
|
+
readonly url: string;
|
|
6
|
+
readonly accept: "application/json" | "text/html";
|
|
7
|
+
readonly operation: OllamaCatalogOperation;
|
|
8
|
+
readonly fetch: OllamaFetch;
|
|
9
|
+
readonly signal: AbortSignal;
|
|
10
|
+
};
|
|
11
|
+
export declare function requestOllamaCatalog(request: CatalogRequest): Promise<string>;
|
|
12
|
+
export {};
|