@sixb/core 0.2.1 → 0.2.2
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/actions/index.js +29 -29
- package/dist/agents/cancel.d.ts.map +1 -1
- package/dist/agents/index.d.ts +5 -3
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +38 -32
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/run-plan.d.ts +15 -1
- package/dist/agents/run-plan.d.ts.map +1 -1
- package/dist/agents/run-session-http.d.ts.map +1 -1
- package/dist/agents/run-session-serve.d.ts.map +1 -1
- package/dist/agents/run-session.d.ts +14 -2
- package/dist/agents/run-session.d.ts.map +1 -1
- package/dist/agents/skills.d.ts +3 -0
- package/dist/agents/skills.d.ts.map +1 -1
- package/dist/agents/step-limits.d.ts +6 -0
- package/dist/agents/step-limits.d.ts.map +1 -1
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.js +1 -1
- package/dist/agents/streams/protocol.d.ts +8 -2
- package/dist/agents/streams/protocol.d.ts.map +1 -1
- package/dist/agents/tool-files.d.ts +3 -1
- package/dist/agents/tool-files.d.ts.map +1 -1
- package/dist/agents/validation.d.ts +1 -1
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/agents/web.d.ts +47 -0
- package/dist/agents/web.d.ts.map +1 -0
- package/dist/artifacts/publish/index.js +16 -16
- package/dist/auth/index.js +3 -3
- package/dist/authorization/index.js +2 -2
- package/dist/authorization/resolve.d.ts +4 -3
- package/dist/authorization/resolve.d.ts.map +1 -1
- package/dist/authorization/types.d.ts +5 -5
- package/dist/authorization/types.d.ts.map +1 -1
- package/dist/bootstrap/index.js +34 -34
- package/dist/{chunk-neftrg0n.js → chunk-0j3crh1w.js} +2 -2
- package/dist/{chunk-tvbmh7tj.js → chunk-2ajw5rz0.js} +14 -10
- package/dist/chunk-2ajw5rz0.js.map +18 -0
- package/dist/{chunk-23s66j86.js → chunk-31kcqmhf.js} +1 -1
- package/dist/{chunk-nghc7eq0.js → chunk-3723kgba.js} +1 -1
- package/dist/{chunk-rjeeyssy.js → chunk-3sqqhpr7.js} +4 -4
- package/dist/{chunk-m3qe54bb.js → chunk-4bm0caep.js} +1 -1
- package/dist/{chunk-h05rg3bx.js → chunk-4s753g3k.js} +3 -3
- package/dist/{chunk-8wsjr52f.js → chunk-5wtnmpze.js} +1 -1
- package/dist/{chunk-edx8xcsm.js → chunk-7z5rkf0m.js} +29 -6
- package/dist/chunk-7z5rkf0m.js.map +13 -0
- package/dist/{chunk-2pk5hjj9.js → chunk-80gym75n.js} +1 -1
- package/dist/{chunk-qbrmpgvv.js → chunk-9whfmsfk.js} +1 -1
- package/dist/{chunk-z3evap21.js → chunk-a5v4gjdx.js} +27 -26
- package/dist/{chunk-z3evap21.js.map → chunk-a5v4gjdx.js.map} +3 -3
- package/dist/{chunk-w53trr0c.js → chunk-a7aa0nzj.js} +5 -5
- package/dist/{chunk-tvefbgvw.js → chunk-az95tsh3.js} +4 -2
- package/dist/chunk-az95tsh3.js.map +11 -0
- package/dist/{chunk-7hd2ez3q.js → chunk-c4nrycdy.js} +1 -1
- package/dist/{chunk-epyfm23v.js → chunk-c706qvyc.js} +3 -3
- package/dist/{chunk-t5daew4g.js → chunk-c7cfe31p.js} +6 -6
- package/dist/{chunk-qsg8rw04.js → chunk-d04g36fw.js} +1 -1
- package/dist/{chunk-ratj7t3t.js → chunk-dsv783c3.js} +305 -32
- package/dist/{chunk-ratj7t3t.js.map → chunk-dsv783c3.js.map} +12 -10
- package/dist/{chunk-cb21tx14.js → chunk-eqgr6nsa.js} +81 -25
- package/dist/{chunk-cb21tx14.js.map → chunk-eqgr6nsa.js.map} +8 -7
- package/dist/{chunk-ax10ft8d.js → chunk-f1h34y3r.js} +5 -5
- package/dist/{chunk-9rh8ncs5.js → chunk-fwsvshr5.js} +1 -1
- package/dist/{chunk-b7a97n8b.js → chunk-ga63a3dz.js} +6 -6
- package/dist/{chunk-b7a97n8b.js.map → chunk-ga63a3dz.js.map} +2 -2
- package/dist/{chunk-cgznz22f.js → chunk-gkv8r794.js} +2 -2
- package/dist/{chunk-t9xyr7y9.js → chunk-j8thxj7w.js} +3 -3
- package/dist/{chunk-31khg3g0.js → chunk-kkjfve0t.js} +73 -2
- package/dist/{chunk-31khg3g0.js.map → chunk-kkjfve0t.js.map} +3 -3
- package/dist/{chunk-8yzhjawq.js → chunk-m2vh8gh0.js} +8 -14
- package/dist/{chunk-8yzhjawq.js.map → chunk-m2vh8gh0.js.map} +3 -3
- package/dist/{chunk-nqnfz3jg.js → chunk-mbc5hvnj.js} +2 -2
- package/dist/{chunk-jk97v21j.js → chunk-n4zzaf6q.js} +3 -2
- package/dist/chunk-n4zzaf6q.js.map +10 -0
- package/dist/{chunk-y2x2935j.js → chunk-nh26e7c5.js} +2 -2
- package/dist/{chunk-jhbk10wf.js → chunk-q9nkpr8k.js} +1 -1
- package/dist/{chunk-47e09r7z.js → chunk-qttqe1ah.js} +86 -6
- package/dist/{chunk-47e09r7z.js.map → chunk-qttqe1ah.js.map} +5 -4
- package/dist/{chunk-3x3bebz7.js → chunk-s7j8ewqv.js} +161 -62
- package/dist/{chunk-3x3bebz7.js.map → chunk-s7j8ewqv.js.map} +7 -6
- package/dist/{chunk-dz7a4t3a.js → chunk-twfreyxr.js} +5 -10
- package/dist/{chunk-dz7a4t3a.js.map → chunk-twfreyxr.js.map} +4 -4
- package/dist/{chunk-ks87m383.js → chunk-w1btn96n.js} +49 -24
- package/dist/{chunk-ks87m383.js.map → chunk-w1btn96n.js.map} +6 -6
- package/dist/{chunk-fg1db9xx.js → chunk-wkq3kvzd.js} +5 -5
- package/dist/chunk-wkq3kvzd.js.map +10 -0
- package/dist/{chunk-aqyjb86c.js → chunk-wrjx1fqz.js} +6 -6
- package/dist/{chunk-agn8d8ys.js → chunk-xtztwpkh.js} +1 -1
- package/dist/{chunk-0g5nyx0k.js → chunk-zeykm8my.js} +2 -2
- package/dist/connectors/connections/runs.d.ts +7 -0
- package/dist/connectors/connections/runs.d.ts.map +1 -1
- package/dist/execution/agent.js +29 -29
- package/dist/execution/object-reader-security.d.ts.map +1 -1
- package/dist/execution/primitive.js +29 -29
- package/dist/execution/request.js +30 -30
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -37
- package/dist/materializer/index.js +15 -15
- package/dist/models/catalog.d.ts +16 -0
- package/dist/models/catalog.d.ts.map +1 -1
- package/dist/models/definitions.d.ts +1 -1
- package/dist/models/definitions.d.ts.map +1 -1
- package/dist/models/execution/index.js +17 -17
- package/dist/models/execution/model-call-recorder.d.ts +1 -1
- package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
- package/dist/models/execution/web-search.d.ts +7 -0
- package/dist/models/execution/web-search.d.ts.map +1 -0
- package/dist/models/index.d.ts +3 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +5 -3
- package/dist/models/index.js.map +1 -1
- package/dist/models/language-model.d.ts +12 -0
- package/dist/models/language-model.d.ts.map +1 -1
- package/dist/models/web-search-model.d.ts +66 -0
- package/dist/models/web-search-model.d.ts.map +1 -0
- package/dist/objects/index.js +29 -29
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/index.d.ts +1 -0
- package/dist/objects/query/index.d.ts.map +1 -1
- package/dist/objects/query/index.js +18 -15
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/query/sort-ties.d.ts +11 -0
- package/dist/objects/query/sort-ties.d.ts.map +1 -0
- package/dist/pipelines/index.js +15 -15
- package/dist/projections/internal.js +15 -15
- package/dist/runtime/create.d.ts +1 -1
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/internal.js +21 -21
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/registry.d.ts +2 -0
- package/dist/security/registry.d.ts.map +1 -1
- package/dist/security/view-conditions.d.ts.map +1 -1
- package/dist/security/visibility-keys.d.ts +19 -0
- package/dist/security/visibility-keys.d.ts.map +1 -0
- package/dist/shares/internal.js +15 -15
- package/dist/storage/agents/in-memory.d.ts +8 -2
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +1 -1
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +8 -2
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +12 -6
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +42 -2
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +4 -4
- package/dist/storage/ai-limits/enforcement.js +3 -3
- package/dist/storage/ai-limits/provider.js +2 -2
- package/dist/storage/connector-connections/provider.js +3 -3
- package/dist/storage/connector-connections/provider.js.map +3 -3
- package/dist/storage/file-upload-sessions/provider.js +4 -4
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +14 -14
- package/dist/storage/internal.js +2 -2
- package/dist/storage/migrations/types.d.ts +6 -0
- package/dist/storage/migrations/types.d.ts.map +1 -1
- package/dist/storage/objects/in-memory/query.d.ts.map +1 -1
- package/dist/storage/objects/index.d.ts +1 -1
- package/dist/storage/objects/index.d.ts.map +1 -1
- package/dist/storage/objects/query-preparation.d.ts +13 -0
- package/dist/storage/objects/query-preparation.d.ts.map +1 -1
- package/dist/storage/objects/read-scope.d.ts.map +1 -1
- package/dist/storage/objects/types.d.ts +52 -0
- package/dist/storage/objects/types.d.ts.map +1 -1
- package/dist/storage/share-grants/provider.js +2 -2
- package/dist/storage/workflow-runs/provider.js +4 -4
- package/dist/syncs/index.js +17 -17
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-limit-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
- package/dist/testing/connector-connection-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.js +399 -45
- package/dist/testing/index.js.map +8 -8
- package/dist/testing/object-conditional-read-scope-contract.d.ts.map +1 -1
- package/dist/testing/object-query-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +15 -15
- package/dist/workflows/index.js +31 -31
- package/package.json +1 -1
- package/src/agents/README.md +2 -1
- package/src/agents/cancel.ts +7 -1
- package/src/agents/index.ts +9 -1
- package/src/agents/run-plan.ts +31 -0
- package/src/agents/run-session-http.ts +15 -12
- package/src/agents/run-session-serve.ts +8 -2
- package/src/agents/run-session.ts +31 -11
- package/src/agents/skills.ts +3 -0
- package/src/agents/step-limits.ts +6 -0
- package/src/agents/streams/protocol.ts +9 -4
- package/src/agents/tool-files.ts +11 -3
- package/src/agents/validation.ts +9 -0
- package/src/agents/web.ts +218 -0
- package/src/authorization/resolve.ts +9 -11
- package/src/authorization/types.ts +5 -5
- package/src/connectors/connections/runs.ts +42 -5
- package/src/execution/object-reader-security.ts +4 -9
- package/src/index.ts +2 -0
- package/src/models/catalog.ts +52 -3
- package/src/models/definitions.ts +2 -0
- package/src/models/execution/README.md +22 -2
- package/src/models/execution/model-call-recorder.ts +1 -1
- package/src/models/execution/web-search.ts +186 -0
- package/src/models/index.ts +12 -0
- package/src/models/language-model.ts +12 -0
- package/src/models/web-search-model.ts +152 -0
- package/src/objects/query/executor.ts +7 -3
- package/src/objects/query/index.ts +1 -0
- package/src/objects/query/sort-ties.ts +16 -0
- package/src/runtime/create.ts +3 -2
- package/src/runtime/resolve-definitions.ts +4 -0
- package/src/security/index.ts +1 -0
- package/src/security/registry.ts +2 -0
- package/src/security/view-conditions.ts +4 -3
- package/src/security/visibility-keys.ts +144 -0
- package/src/storage/agents/in-memory.ts +29 -2
- package/src/storage/agents/index.ts +2 -0
- package/src/storage/agents/provider.ts +57 -1
- package/src/storage/agents/types.ts +45 -2
- package/src/storage/connector-connections/in-memory.ts +2 -2
- package/src/storage/connector-connections/provider/connections.ts +2 -2
- package/src/storage/index.ts +4 -0
- package/src/storage/migrations/types.ts +6 -0
- package/src/storage/objects/in-memory/query.ts +5 -2
- package/src/storage/objects/index.ts +2 -0
- package/src/storage/objects/query-preparation.ts +59 -1
- package/src/storage/objects/read-scope.ts +108 -2
- package/src/storage/objects/types.ts +43 -0
- package/src/testing/agent-storage-contract.ts +70 -0
- package/src/testing/ai-limit-storage-contract.ts +11 -1
- package/src/testing/ai-usage-storage-contract.ts +15 -2
- package/src/testing/connector-connection-storage-contract.ts +23 -0
- package/src/testing/object-conditional-read-scope-contract.ts +267 -5
- package/src/testing/object-query-contract.ts +75 -0
- package/dist/chunk-edx8xcsm.js.map +0 -13
- package/dist/chunk-fg1db9xx.js.map +0 -10
- package/dist/chunk-jk97v21j.js.map +0 -10
- package/dist/chunk-tvbmh7tj.js.map +0 -18
- package/dist/chunk-tvefbgvw.js.map +0 -11
- /package/dist/{chunk-neftrg0n.js.map → chunk-0j3crh1w.js.map} +0 -0
- /package/dist/{chunk-23s66j86.js.map → chunk-31kcqmhf.js.map} +0 -0
- /package/dist/{chunk-nghc7eq0.js.map → chunk-3723kgba.js.map} +0 -0
- /package/dist/{chunk-rjeeyssy.js.map → chunk-3sqqhpr7.js.map} +0 -0
- /package/dist/{chunk-m3qe54bb.js.map → chunk-4bm0caep.js.map} +0 -0
- /package/dist/{chunk-h05rg3bx.js.map → chunk-4s753g3k.js.map} +0 -0
- /package/dist/{chunk-8wsjr52f.js.map → chunk-5wtnmpze.js.map} +0 -0
- /package/dist/{chunk-2pk5hjj9.js.map → chunk-80gym75n.js.map} +0 -0
- /package/dist/{chunk-qbrmpgvv.js.map → chunk-9whfmsfk.js.map} +0 -0
- /package/dist/{chunk-w53trr0c.js.map → chunk-a7aa0nzj.js.map} +0 -0
- /package/dist/{chunk-7hd2ez3q.js.map → chunk-c4nrycdy.js.map} +0 -0
- /package/dist/{chunk-epyfm23v.js.map → chunk-c706qvyc.js.map} +0 -0
- /package/dist/{chunk-t5daew4g.js.map → chunk-c7cfe31p.js.map} +0 -0
- /package/dist/{chunk-qsg8rw04.js.map → chunk-d04g36fw.js.map} +0 -0
- /package/dist/{chunk-ax10ft8d.js.map → chunk-f1h34y3r.js.map} +0 -0
- /package/dist/{chunk-9rh8ncs5.js.map → chunk-fwsvshr5.js.map} +0 -0
- /package/dist/{chunk-cgznz22f.js.map → chunk-gkv8r794.js.map} +0 -0
- /package/dist/{chunk-t9xyr7y9.js.map → chunk-j8thxj7w.js.map} +0 -0
- /package/dist/{chunk-nqnfz3jg.js.map → chunk-mbc5hvnj.js.map} +0 -0
- /package/dist/{chunk-y2x2935j.js.map → chunk-nh26e7c5.js.map} +0 -0
- /package/dist/{chunk-jhbk10wf.js.map → chunk-q9nkpr8k.js.map} +0 -0
- /package/dist/{chunk-aqyjb86c.js.map → chunk-wrjx1fqz.js.map} +0 -0
- /package/dist/{chunk-agn8d8ys.js.map → chunk-xtztwpkh.js.map} +0 -0
- /package/dist/{chunk-0g5nyx0k.js.map → chunk-zeykm8my.js.map} +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { createSixbError } from "../errors/internal"
|
|
2
|
+
import type { ModelCatalog } from "../models/catalog"
|
|
3
|
+
import type { AiModelCallRecorder } from "../models/execution/model-call-recorder"
|
|
4
|
+
import { bindWebSearchModels } from "../models/execution/web-search"
|
|
5
|
+
import { RuntimeError } from "../runtime/errors"
|
|
6
|
+
import type { AgentRunModels } from "./run-session"
|
|
7
|
+
import type { AgentDefinitions } from "./skills"
|
|
8
|
+
|
|
9
|
+
// The Agent's web tools: the option that narrows or turns them off, the domain lists both tools
|
|
10
|
+
// apply, and the search a run's tool calls through its own accounting.
|
|
11
|
+
|
|
12
|
+
/** Narrows what the Agent's web tools reach. */
|
|
13
|
+
export interface AgentWebOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Only these: `docs.example.com`, `*.example.com` (its subdomains, not itself) or a path prefix
|
|
16
|
+
* such as `example.com/guides`.
|
|
17
|
+
*/
|
|
18
|
+
readonly allowedDomains?: readonly string[]
|
|
19
|
+
/** Never these, in the same syntax; they win over `allowedDomains`. */
|
|
20
|
+
readonly blockedDomains?: readonly string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The tool names Sixb gives the Agent for the web, offered unless `agent.web` is `false`. */
|
|
24
|
+
export const AGENT_WEB_TOOL_NAMES = ["web_search", "web_fetch"] as const
|
|
25
|
+
|
|
26
|
+
const MAX_DOMAINS = 1_200
|
|
27
|
+
const MAX_RULE_CHARACTERS = 4_096
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check `agent.web` and return it with each domain rule in its canonical form: lowercase, without
|
|
31
|
+
* a trailing dot or slash, duplicates dropped.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveAgentWebOptions(value: unknown): false | AgentWebOptions | undefined {
|
|
34
|
+
if (value === undefined || value === false) return value
|
|
35
|
+
|
|
36
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
37
|
+
throw new RuntimeError(
|
|
38
|
+
"[Sixb] agent.web must be false, or { allowedDomains?, blockedDomains? }."
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const key of Object.keys(value)) {
|
|
43
|
+
if (key !== "allowedDomains" && key !== "blockedDomains") {
|
|
44
|
+
throw new RuntimeError(
|
|
45
|
+
`[Sixb] agent.web has an unknown option '${key}': use allowedDomains or blockedDomains.`
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const options = value as Record<string, unknown>
|
|
51
|
+
const allowedDomains = canonicalRules(options.allowedDomains, "allowedDomains")
|
|
52
|
+
const blockedDomains = canonicalRules(options.blockedDomains, "blockedDomains")
|
|
53
|
+
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
...(allowedDomains ? { allowedDomains } : {}),
|
|
56
|
+
...(blockedDomains ? { blockedDomains } : {}),
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Refuse a language model whose provider runs a tool under a name the Agent's web tools take: a
|
|
62
|
+
* request would declare the name twice. Checked unless `agent.web` is `false`; `web_search` only
|
|
63
|
+
* when the project has a search backend, since the Agent offers none without one.
|
|
64
|
+
*/
|
|
65
|
+
export function assertNoProviderWebTools(models: ModelCatalog | undefined): void {
|
|
66
|
+
const offered: readonly string[] = models?.webSearch ? AGENT_WEB_TOOL_NAMES : ["web_fetch"]
|
|
67
|
+
|
|
68
|
+
for (const { provider, modelId, model } of models?.language?.list() ?? []) {
|
|
69
|
+
const name = model.providerToolNames?.find((tool) => offered.includes(tool))
|
|
70
|
+
if (name === undefined) continue
|
|
71
|
+
|
|
72
|
+
throw new RuntimeError(
|
|
73
|
+
`[Sixb] Language model '${provider}/${modelId}' declares the provider tool '${name}', a name Sixb gives the Agent's own web tool. Remove it from providerTools, or set agent.web: false to keep the provider's.`
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** What the domain lists say of a URL. */
|
|
79
|
+
export interface WebDomainPolicy {
|
|
80
|
+
/** Why the lists refuse the URL, or undefined when they allow it. */
|
|
81
|
+
refuses(url: URL): "blocked" | "not-allowed" | undefined
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Compile domain lists `resolveAgentWebOptions` already checked. */
|
|
85
|
+
export function webDomainPolicy(options: AgentWebOptions): WebDomainPolicy {
|
|
86
|
+
const allowed = options.allowedDomains?.map((rule) => parseRule(rule, "allowedDomains"))
|
|
87
|
+
const blocked = options.blockedDomains?.map((rule) => parseRule(rule, "blockedDomains"))
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
refuses(url) {
|
|
91
|
+
if (blocked?.some((rule) => matchesRule(url, rule))) return "blocked"
|
|
92
|
+
if (allowed && !allowed.some((rule) => matchesRule(url, rule))) return "not-allowed"
|
|
93
|
+
return undefined
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A run's web search, through the project's web search model: admitted, bounded and recorded with
|
|
100
|
+
* the run's other model calls.
|
|
101
|
+
*/
|
|
102
|
+
export function bindAgentWebSearch(
|
|
103
|
+
definitions: {
|
|
104
|
+
readonly agent: Pick<AgentDefinitions, "web">
|
|
105
|
+
readonly models?: Pick<ModelCatalog, "webSearch">
|
|
106
|
+
},
|
|
107
|
+
execution: {
|
|
108
|
+
/** Aborts once the run ends or is cancelled. */
|
|
109
|
+
readonly signal: AbortSignal
|
|
110
|
+
readonly accounting: () => Promise<AiModelCallRecorder>
|
|
111
|
+
}
|
|
112
|
+
): AgentRunModels["webSearch"] {
|
|
113
|
+
const bound = bindWebSearchModels(definitions.models?.webSearch, {
|
|
114
|
+
signal: (signal) => (signal ? AbortSignal.any([execution.signal, signal]) : execution.signal),
|
|
115
|
+
accounting: execution.accounting,
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
return async (request, signal) => {
|
|
119
|
+
// A runner asks for a search through its session: the project's options decide, not its plan.
|
|
120
|
+
if (definitions.agent.web === false) {
|
|
121
|
+
throw createSixbError(
|
|
122
|
+
"agent.execution_failed",
|
|
123
|
+
"[Sixb] The Agent's web tools are off: agent.web is false."
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!bound) {
|
|
128
|
+
throw createSixbError(
|
|
129
|
+
"agent.execution_failed",
|
|
130
|
+
"[Sixb] The project has no web search model: set models.webSearch, or use a language model that offers one."
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return bound.default.model.search({ ...request, signal })
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface DomainRule {
|
|
139
|
+
readonly hostname: string
|
|
140
|
+
readonly wildcard: boolean
|
|
141
|
+
readonly pathPrefix?: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function canonicalRules(value: unknown, field: string): readonly string[] | undefined {
|
|
145
|
+
if (value === undefined) return undefined
|
|
146
|
+
|
|
147
|
+
if (!Array.isArray(value) || value.length < 1 || value.length > MAX_DOMAINS) {
|
|
148
|
+
throw new RuntimeError(`[Sixb] agent.web.${field} must list from 1 to ${MAX_DOMAINS} domains.`)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const rules = new Set<string>()
|
|
152
|
+
for (const entry of value) rules.add(canonicalRule(parseRule(entry, field)))
|
|
153
|
+
|
|
154
|
+
return Object.freeze([...rules])
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function parseRule(value: unknown, field: string): DomainRule {
|
|
158
|
+
if (typeof value !== "string") throw invalidRule(field, value)
|
|
159
|
+
|
|
160
|
+
const trimmed = value.trim()
|
|
161
|
+
if (!trimmed || trimmed.length > MAX_RULE_CHARACTERS || /[\\?#]/.test(trimmed)) {
|
|
162
|
+
throw invalidRule(field, value)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const wildcard = trimmed.startsWith("*.")
|
|
166
|
+
const filter = wildcard ? trimmed.slice(2) : trimmed
|
|
167
|
+
const authority = filter.split("/", 1)[0] ?? ""
|
|
168
|
+
if (!authority || /[*:@]/.test(authority)) throw invalidRule(field, value)
|
|
169
|
+
|
|
170
|
+
let parsed: URL
|
|
171
|
+
try {
|
|
172
|
+
parsed = new URL(`https://${filter}`)
|
|
173
|
+
} catch {
|
|
174
|
+
throw invalidRule(field, value)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const hostname = canonicalHostname(parsed.hostname)
|
|
178
|
+
if (!isValidHostname(hostname)) throw invalidRule(field, value)
|
|
179
|
+
|
|
180
|
+
const pathPrefix = parsed.pathname.replace(/\/+$/, "")
|
|
181
|
+
return { hostname, wildcard, ...(pathPrefix ? { pathPrefix } : {}) }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function canonicalRule(rule: DomainRule): string {
|
|
185
|
+
return `${rule.wildcard ? "*." : ""}${rule.hostname}${rule.pathPrefix ?? ""}`
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function matchesRule(url: URL, rule: DomainRule): boolean {
|
|
189
|
+
const hostname = canonicalHostname(url.hostname)
|
|
190
|
+
const hostnameMatches = rule.wildcard
|
|
191
|
+
? hostname !== rule.hostname && hostname.endsWith(`.${rule.hostname}`)
|
|
192
|
+
: hostname === rule.hostname
|
|
193
|
+
if (!hostnameMatches) return false
|
|
194
|
+
|
|
195
|
+
if (!rule.pathPrefix) return true
|
|
196
|
+
return url.pathname === rule.pathPrefix || url.pathname.startsWith(`${rule.pathPrefix}/`)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function canonicalHostname(value: string): string {
|
|
200
|
+
return value.toLowerCase().replace(/\.$/, "")
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function isValidHostname(hostname: string): boolean {
|
|
204
|
+
if (!hostname || hostname.length > 253) return false
|
|
205
|
+
|
|
206
|
+
return hostname
|
|
207
|
+
.split(".")
|
|
208
|
+
.every(
|
|
209
|
+
(label) =>
|
|
210
|
+
label.length >= 1 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label)
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function invalidRule(field: string, value: unknown): RuntimeError {
|
|
215
|
+
return new RuntimeError(
|
|
216
|
+
`[Sixb] agent.web.${field} has an invalid entry ${JSON.stringify(value)}: write a domain such as 'example.com', '*.example.com' or 'example.com/docs', without a scheme, port, query or credentials.`
|
|
217
|
+
)
|
|
218
|
+
}
|
|
@@ -53,8 +53,9 @@ export function resolveRoleGrants(role: RoleDefinition, universe: GrantUniverse)
|
|
|
53
53
|
* Resolve a role's conditional view grants once at startup, from their validated conditions.
|
|
54
54
|
*
|
|
55
55
|
* A condition applies to the type its grant names and to each subtype, as a view grant does.
|
|
56
|
-
* Several conditions on one type
|
|
57
|
-
*
|
|
56
|
+
* Several conditions on one type stay apart: the role shows what any of them matches, and each
|
|
57
|
+
* keeps the index storage prepared for it. A type the role also views without a condition drops
|
|
58
|
+
* them: the role shows every object of it.
|
|
58
59
|
*/
|
|
59
60
|
export function resolveRoleViewConditions(
|
|
60
61
|
conditions: readonly {
|
|
@@ -63,7 +64,7 @@ export function resolveRoleViewConditions(
|
|
|
63
64
|
}[],
|
|
64
65
|
grants: GrantIndex,
|
|
65
66
|
universe: GrantUniverse
|
|
66
|
-
): ReadonlyMap<string, ObjectQueryPredicate> {
|
|
67
|
+
): ReadonlyMap<string, readonly ObjectQueryPredicate[]> {
|
|
67
68
|
const byType = new Map<string, ObjectQueryPredicate[]>()
|
|
68
69
|
|
|
69
70
|
for (const condition of conditions) {
|
|
@@ -79,15 +80,12 @@ export function resolveRoleViewConditions(
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
return new Map(
|
|
82
|
-
[...byType].map(
|
|
83
|
+
[...byType].map(
|
|
84
|
+
([objectTypeId, predicates]) => [objectTypeId, Object.freeze(predicates)] as const
|
|
85
|
+
)
|
|
83
86
|
)
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
function anyOf(predicates: readonly ObjectQueryPredicate[]): ObjectQueryPredicate {
|
|
87
|
-
if (predicates.length === 1) return predicates[0]!
|
|
88
|
-
return Object.freeze({ op: "or", items: Object.freeze([...predicates]) })
|
|
89
|
-
}
|
|
90
|
-
|
|
91
89
|
function expandSelection(
|
|
92
90
|
selection: Selection,
|
|
93
91
|
universe: ReadonlySet<string>,
|
|
@@ -153,8 +151,8 @@ export function resolveAuthorizationContext(input: {
|
|
|
153
151
|
for (const markingId of role.clearances ?? []) {
|
|
154
152
|
clearances.add(markingId)
|
|
155
153
|
}
|
|
156
|
-
for (const [objectTypeId,
|
|
157
|
-
viewConditions.set(objectTypeId, [...(viewConditions.get(objectTypeId) ?? []),
|
|
154
|
+
for (const [objectTypeId, predicates] of role.viewConditions ?? []) {
|
|
155
|
+
viewConditions.set(objectTypeId, [...(viewConditions.get(objectTypeId) ?? []), ...predicates])
|
|
158
156
|
}
|
|
159
157
|
}
|
|
160
158
|
|
|
@@ -45,10 +45,10 @@ export interface ResolvedRole {
|
|
|
45
45
|
readonly grants: GrantIndex
|
|
46
46
|
/**
|
|
47
47
|
* What the role's `can.view(Type).where(...)` grants show, per concrete type: the type's
|
|
48
|
-
* conditions,
|
|
49
|
-
* `grants["view:object"]` and not here. Absent means none.
|
|
48
|
+
* conditions, any of which shows an object. A type the role also views without a condition is
|
|
49
|
+
* in `grants["view:object"]` and not here. Absent means none.
|
|
50
50
|
*/
|
|
51
|
-
readonly viewConditions?: ReadonlyMap<string, ObjectQueryPredicate>
|
|
51
|
+
readonly viewConditions?: ReadonlyMap<string, readonly ObjectQueryPredicate[]>
|
|
52
52
|
/** Marking ids this role clears. Absent means none. */
|
|
53
53
|
readonly clearances?: ReadonlySet<string>
|
|
54
54
|
}
|
|
@@ -61,8 +61,8 @@ export interface AuthorizationContext {
|
|
|
61
61
|
readonly roleIds: readonly string[]
|
|
62
62
|
readonly grants: GrantIndex
|
|
63
63
|
/**
|
|
64
|
-
* The object types the principal views only where a condition matches, with
|
|
65
|
-
*
|
|
64
|
+
* The object types the principal views only where a condition matches, with every condition
|
|
65
|
+
* its roles put on each. A type in `grants["view:object"]` is never here, so a check on that grant
|
|
66
66
|
* denies these types; only the authorized object reader reads them, through these conditions.
|
|
67
67
|
* Absent means none.
|
|
68
68
|
*/
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type Storage,
|
|
11
11
|
} from "../../storage"
|
|
12
12
|
import { createConnectorCodedError, isConnectorStorageError, storageBoundaryError } from "../errors"
|
|
13
|
+
import type { ConnectorAccountCandidate } from "../types"
|
|
13
14
|
import {
|
|
14
15
|
assertConnectorAuthorizationActor,
|
|
15
16
|
type DefaultConnectorAuthorizationLifecycle,
|
|
@@ -326,19 +327,28 @@ export class ConnectorConnectionRunService {
|
|
|
326
327
|
)
|
|
327
328
|
}
|
|
328
329
|
|
|
330
|
+
return this.view(await this.connectRunAccount(run, account, input.replace === true))
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** Fills the run's slot with one of its authorization's accounts and finishes the run. */
|
|
334
|
+
private async connectRunAccount(
|
|
335
|
+
run: ConnectorConnectionRunRecord,
|
|
336
|
+
account: ConnectorAccountCandidate,
|
|
337
|
+
replace: boolean
|
|
338
|
+
): Promise<ConnectorConnectionRunRecord> {
|
|
329
339
|
let selected: Awaited<ReturnType<ConnectorConnectionStorage["putConnectionFromRun"]>>
|
|
330
340
|
try {
|
|
331
341
|
selected = await this.connectionStorage.putConnectionFromRun({
|
|
332
342
|
id: `ccn_${randomUUID()}`,
|
|
333
343
|
projectId: this.projectId,
|
|
334
|
-
connectorId:
|
|
344
|
+
connectorId: run.connectorId,
|
|
335
345
|
runId: run.id,
|
|
336
346
|
account,
|
|
337
|
-
replace
|
|
347
|
+
replace,
|
|
338
348
|
})
|
|
339
349
|
} catch (error) {
|
|
340
350
|
if (isConnectorStorageError(error, "run_invalid")) {
|
|
341
|
-
const latest = await this.readRun(
|
|
351
|
+
const latest = await this.readRun(run.connectorId, run.id)
|
|
342
352
|
if (latest) await this.continueRunCleanup(latest)
|
|
343
353
|
throw createConnectorCodedError(
|
|
344
354
|
"connector.operation_conflict",
|
|
@@ -364,7 +374,7 @@ export class ConnectorConnectionRunService {
|
|
|
364
374
|
}
|
|
365
375
|
const cleanupCompleted = selected.revocationPendingAuthorizationId
|
|
366
376
|
? await this.continuePendingRevocation(
|
|
367
|
-
|
|
377
|
+
run.connectorId,
|
|
368
378
|
selected.revocationPendingAuthorizationId
|
|
369
379
|
)
|
|
370
380
|
: true
|
|
@@ -373,7 +383,26 @@ export class ConnectorConnectionRunService {
|
|
|
373
383
|
} else {
|
|
374
384
|
this.scheduleRunMaintenance(selected.run, CLEANUP_RETRY_DELAY_MS)
|
|
375
385
|
}
|
|
376
|
-
return
|
|
386
|
+
return selected.run
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* A grant with one account leaves the user nothing to choose. The run is already waiting, so any
|
|
391
|
+
* failure here falls back to the picker with the grant intact.
|
|
392
|
+
*/
|
|
393
|
+
private async connectOnlyAccount(
|
|
394
|
+
run: ConnectorConnectionRunRecord,
|
|
395
|
+
account: ConnectorAccountCandidate
|
|
396
|
+
): Promise<void> {
|
|
397
|
+
try {
|
|
398
|
+
await this.connectRunAccount(run, account, false)
|
|
399
|
+
} catch (error) {
|
|
400
|
+
if (isSixbError(error) && error.code === "connector.replacement_required") return
|
|
401
|
+
console.warn(
|
|
402
|
+
"[Sixb] Connecting the only connector account failed; the user can still select it.",
|
|
403
|
+
error
|
|
404
|
+
)
|
|
405
|
+
}
|
|
377
406
|
}
|
|
378
407
|
|
|
379
408
|
private async claimCallback(state: string, callbackBinding: string, redirectUri: string) {
|
|
@@ -440,6 +469,12 @@ export class ConnectorConnectionRunService {
|
|
|
440
469
|
authorization: ConnectorAuthorizationRecord
|
|
441
470
|
): Promise<ConnectorConnectionRunRecord> {
|
|
442
471
|
if (run.kind === "connect") {
|
|
472
|
+
if (authorization.accounts.length === 0) {
|
|
473
|
+
throw createConnectorCodedError(
|
|
474
|
+
"connector.not_found",
|
|
475
|
+
"This authorization does not give access to any account. Sign in with one that has access."
|
|
476
|
+
)
|
|
477
|
+
}
|
|
443
478
|
if (!authorization.selectionExpiresAt) {
|
|
444
479
|
throw createConnectorCodedError(
|
|
445
480
|
"internal.unexpected",
|
|
@@ -461,6 +496,8 @@ export class ConnectorConnectionRunService {
|
|
|
461
496
|
)
|
|
462
497
|
if (waiting) {
|
|
463
498
|
this.scheduleRunMaintenance(waiting, this.selectionTtlMs + 1)
|
|
499
|
+
const [account, ...others] = authorization.accounts
|
|
500
|
+
if (account && others.length === 0) await this.connectOnlyAccount(waiting, account)
|
|
464
501
|
return waiting
|
|
465
502
|
}
|
|
466
503
|
} else {
|
|
@@ -2,7 +2,6 @@ import { assertAuthorized, assertRuntimeAuthorizationBound, isAllowed } from "..
|
|
|
2
2
|
import { AuthorizationError } from "../authorization/errors"
|
|
3
3
|
import type { AuthorizationContext } from "../authorization/types"
|
|
4
4
|
import { type Unreadable, unreadableError } from "../objects/property-clearance"
|
|
5
|
-
import { bindCurrentUserPredicate } from "../objects/query/current-user"
|
|
6
5
|
import type { ObjectQueryPredicate } from "../objects/query/ir"
|
|
7
6
|
import {
|
|
8
7
|
createSelectedObjectQueryAdmission,
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
import type { OntologyRegistry } from "../ontology"
|
|
12
11
|
import type { UserRef } from "../ontology/user-ref"
|
|
13
12
|
import type { AppliedMarkings } from "../security/applied-markings"
|
|
13
|
+
import { viewConditionReadCondition } from "../security/visibility-keys"
|
|
14
14
|
import type {
|
|
15
15
|
CompiledConditionalObjectReadScope,
|
|
16
16
|
CompiledObjectReadStep,
|
|
@@ -108,10 +108,9 @@ export class ObjectReaderSecurity {
|
|
|
108
108
|
|
|
109
109
|
this.conditionalScope = compileConditionalObjectReadScope({
|
|
110
110
|
kind: "conditional",
|
|
111
|
-
conditions: [...conditions].map(([objectTypeId, predicates]) =>
|
|
112
|
-
objectTypeId,
|
|
113
|
-
|
|
114
|
-
})),
|
|
111
|
+
conditions: [...conditions].map(([objectTypeId, predicates]) =>
|
|
112
|
+
viewConditionReadCondition(objectTypeId, predicates, grantee)
|
|
113
|
+
),
|
|
115
114
|
})
|
|
116
115
|
}
|
|
117
116
|
|
|
@@ -238,10 +237,6 @@ function propertiesReadBy(predicate: ObjectQueryPredicate): readonly string[] {
|
|
|
238
237
|
}
|
|
239
238
|
}
|
|
240
239
|
|
|
241
|
-
function anyOf(predicates: readonly ObjectQueryPredicate[]): ObjectQueryPredicate {
|
|
242
|
-
return predicates.length === 1 ? predicates[0]! : { op: "or", items: predicates }
|
|
243
|
-
}
|
|
244
|
-
|
|
245
240
|
/**
|
|
246
241
|
* Unrestricted authority reads every property. A principal reads what its roles clear; delegated
|
|
247
242
|
* shared access carries no clearance, so no share can expose a marked property.
|
package/src/index.ts
CHANGED
|
@@ -485,6 +485,7 @@ export type {
|
|
|
485
485
|
Selection,
|
|
486
486
|
ShareGrant,
|
|
487
487
|
UsersViewGrant,
|
|
488
|
+
ViewCondition,
|
|
488
489
|
ViewGrant,
|
|
489
490
|
ViewGrantTarget,
|
|
490
491
|
} from "./security"
|
|
@@ -1232,6 +1233,7 @@ export type {
|
|
|
1232
1233
|
AgentToolRuntimeFacade,
|
|
1233
1234
|
AgentToolTextContent,
|
|
1234
1235
|
AgentUsageReference,
|
|
1236
|
+
AgentWebOptions,
|
|
1235
1237
|
InferAgentToolInput,
|
|
1236
1238
|
InferAgentToolInputSchema,
|
|
1237
1239
|
InferAgentToolOutput,
|
package/src/models/catalog.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
modelReasoningSupportIssue,
|
|
22
22
|
} from "./language-model"
|
|
23
23
|
import { assertRerankingModel, type RerankingModel } from "./reranking-model"
|
|
24
|
+
import { assertWebSearchModel, type WebSearchModel } from "./web-search-model"
|
|
24
25
|
|
|
25
26
|
/** Stable identity of a configured provider binding. */
|
|
26
27
|
export interface ModelRef {
|
|
@@ -48,6 +49,17 @@ export interface RerankingModelCatalog {
|
|
|
48
49
|
getByRef(ref: ModelRef): RerankingModelEntry | null
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
export interface WebSearchModelEntry extends ModelRef {
|
|
53
|
+
readonly model: WebSearchModel
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface WebSearchModelCatalog {
|
|
57
|
+
/** The one Sixb searches with. */
|
|
58
|
+
readonly default: WebSearchModelEntry
|
|
59
|
+
list(): readonly WebSearchModelEntry[]
|
|
60
|
+
getByRef(ref: ModelRef): WebSearchModelEntry | null
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
/** The cost and strength classes a project can configure language models in. */
|
|
52
64
|
export const LANGUAGE_MODEL_TIERS = ["light", "standard", "heavy"] as const
|
|
53
65
|
|
|
@@ -107,6 +119,7 @@ export interface ModelCatalog {
|
|
|
107
119
|
readonly embedding: EmbeddingModelCatalog
|
|
108
120
|
readonly image?: ImageModelCatalog
|
|
109
121
|
readonly reranking?: RerankingModelCatalog
|
|
122
|
+
readonly webSearch?: WebSearchModelCatalog
|
|
110
123
|
}
|
|
111
124
|
|
|
112
125
|
export interface ModelCatalogInput {
|
|
@@ -123,6 +136,11 @@ export interface ModelCatalogInput {
|
|
|
123
136
|
readonly image?: readonly ImageModel[]
|
|
124
137
|
/** Available rerankers; no default model and no automatic activation. */
|
|
125
138
|
readonly reranking?: readonly RerankingModel[]
|
|
139
|
+
/**
|
|
140
|
+
* Ordered; the first is the one Sixb searches with. Omitted, Sixb searches with the default
|
|
141
|
+
* language model's own web search, else the first language model that offers one.
|
|
142
|
+
*/
|
|
143
|
+
readonly webSearch?: readonly WebSearchModel[]
|
|
126
144
|
}
|
|
127
145
|
|
|
128
146
|
// Only statically required inputs make their corresponding catalogs required.
|
|
@@ -166,6 +184,7 @@ export function createModelCatalog(input: ModelCatalogInput): ModelCatalog {
|
|
|
166
184
|
const audio = createAudioCatalog(input.audio)
|
|
167
185
|
const image = createImageCatalog(input.image)
|
|
168
186
|
const reranking = createRerankingCatalog(input.reranking)
|
|
187
|
+
const webSearch = createWebSearchCatalog(input.webSearch, language)
|
|
169
188
|
|
|
170
189
|
if (
|
|
171
190
|
!language &&
|
|
@@ -173,14 +192,15 @@ export function createModelCatalog(input: ModelCatalogInput): ModelCatalog {
|
|
|
173
192
|
!audio &&
|
|
174
193
|
!image &&
|
|
175
194
|
embedding.list().length === 0 &&
|
|
176
|
-
!reranking?.list().length
|
|
195
|
+
!reranking?.list().length &&
|
|
196
|
+
!webSearch
|
|
177
197
|
) {
|
|
178
198
|
throw new RuntimeError(
|
|
179
|
-
"[Sixb] Configure at least one language, embedding, decision, audio, image or
|
|
199
|
+
"[Sixb] Configure at least one language, embedding, decision, audio, image, reranking or web search model."
|
|
180
200
|
)
|
|
181
201
|
}
|
|
182
202
|
|
|
183
|
-
return Object.freeze({ language, embedding, decision, audio, image, reranking })
|
|
203
|
+
return Object.freeze({ language, embedding, decision, audio, image, reranking, webSearch })
|
|
184
204
|
}
|
|
185
205
|
|
|
186
206
|
function createRerankingCatalog(
|
|
@@ -193,6 +213,35 @@ function createRerankingCatalog(
|
|
|
193
213
|
return indexModelBindings(models, "reranking", assertRerankingModel)
|
|
194
214
|
}
|
|
195
215
|
|
|
216
|
+
/**
|
|
217
|
+
* The project's own list, else the search its default language model offers, else the first
|
|
218
|
+
* language model's that offers one. Discovered, the catalog holds that one search alone.
|
|
219
|
+
*/
|
|
220
|
+
function createWebSearchCatalog(
|
|
221
|
+
models: readonly WebSearchModel[] | undefined,
|
|
222
|
+
language: LanguageModelCatalog | undefined
|
|
223
|
+
): WebSearchModelCatalog | undefined {
|
|
224
|
+
if (models !== undefined && !Array.isArray(models)) {
|
|
225
|
+
throw new RuntimeError("[Sixb] models.webSearch must be an array of web search models.")
|
|
226
|
+
}
|
|
227
|
+
if (models?.length === 0) {
|
|
228
|
+
throw new RuntimeError(
|
|
229
|
+
"[Sixb] models.webSearch must contain at least one model. Omit it to search with your language models' own web search."
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const discovered =
|
|
234
|
+
language?.default.model.webSearch ??
|
|
235
|
+
language?.list().find((entry) => entry.model.webSearch)?.model.webSearch
|
|
236
|
+
const configured = models ?? (discovered ? [discovered] : [])
|
|
237
|
+
|
|
238
|
+
const index = indexModelBindings(configured, "webSearch", assertWebSearchModel)
|
|
239
|
+
const [defaultEntry] = index.list()
|
|
240
|
+
if (!defaultEntry) return undefined
|
|
241
|
+
|
|
242
|
+
return Object.freeze({ ...index, default: defaultEntry })
|
|
243
|
+
}
|
|
244
|
+
|
|
196
245
|
function createLanguageCatalog(
|
|
197
246
|
input: ModelCatalogInput["language"]
|
|
198
247
|
): LanguageModelCatalog | undefined {
|
|
@@ -15,6 +15,7 @@ export const MODEL_KINDS = [
|
|
|
15
15
|
"transcription",
|
|
16
16
|
"speech",
|
|
17
17
|
"reranking",
|
|
18
|
+
"web-search",
|
|
18
19
|
] as const
|
|
19
20
|
|
|
20
21
|
export type ModelKind = (typeof MODEL_KINDS)[number]
|
|
@@ -26,6 +27,7 @@ export type ModelKind = (typeof MODEL_KINDS)[number]
|
|
|
26
27
|
export const TOKENLESS_MODEL_KINDS: readonly ModelKind[] = [
|
|
27
28
|
"transcription",
|
|
28
29
|
"reranking",
|
|
30
|
+
"web-search",
|
|
29
31
|
"image",
|
|
30
32
|
"speech",
|
|
31
33
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Model execution accounting
|
|
2
2
|
|
|
3
|
-
Internal execution and accounting shared by language, embedding, decision, reranking, image and speech calls. Application usage is
|
|
3
|
+
Internal execution and accounting shared by language, embedding, decision, reranking, web search, image and speech calls. Application usage is
|
|
4
4
|
documented in [Usage and limits](../../../../../docs/models/usage-and-limits.md).
|
|
5
5
|
|
|
6
6
|
## Execution boundary
|
|
@@ -78,11 +78,31 @@ and ranking validation. A complete permutation with finite scores is required; t
|
|
|
78
78
|
candidate order. `RerankingModelResponseError` carries metadata from malformed billable responses.
|
|
79
79
|
|
|
80
80
|
Provider charges remain distinct from token usage: absent tokens stay unknown. Token limits
|
|
81
|
-
neither admit nor count reranking, transcription, image or speech calls (`aiLimitMeterApplies` in
|
|
81
|
+
neither admit nor count reranking, web search, transcription, image or speech calls (`aiLimitMeterApplies` in
|
|
82
82
|
the limit storage helpers), so their unmetered records cannot make a token meter unavailable. Reported
|
|
83
83
|
costs reconcile monetary reservations; missing tariffs fail admission under cost limits. Recovery
|
|
84
84
|
remains the existing accounting-only replay.
|
|
85
85
|
|
|
86
|
+
## Web search flow
|
|
87
|
+
|
|
88
|
+
`web-search.ts` binds the catalog to a session the way `reranking.ts` does; an Agent run can bind
|
|
89
|
+
it to its own recorder, since it needs only a signal and accounting. The catalog's default is
|
|
90
|
+
`models.webSearch[0]`, else the default language binding's `webSearch`, else the first language
|
|
91
|
+
binding's.
|
|
92
|
+
|
|
93
|
+
The request is snapshotted, `maxResults` clamped to 1–10, and the call bounded at 30 seconds with
|
|
94
|
+
no retry. Admission reserves the binding's `estimateReservation({ maxResults })`; without one, cost
|
|
95
|
+
limits refuse the search, as they do transcription. No rate card prices a search, so its cost is
|
|
96
|
+
what the provider reports. The call is recorded before its hits are checked: a malformed reply, or
|
|
97
|
+
a `WebSearchModelResponseError` carrying its metadata, is still accounted. Results must be a list of
|
|
98
|
+
hits with a title and a snippet; a hit without an http(s) URL is dropped, not the reply. Sixb cuts
|
|
99
|
+
snippets to 300 characters and keeps only dates that parse.
|
|
100
|
+
|
|
101
|
+
A search that fails without a reply (an HTTP error, a network failure, the timeout, an abort) is
|
|
102
|
+
not recorded: whether it was billed is unknown, so its reservation is kept as unknown, as for a
|
|
103
|
+
language call. An unpriced record would leave every cost limit unable to count, refusing each call
|
|
104
|
+
it covers until the period ends.
|
|
105
|
+
|
|
86
106
|
## Decision flow
|
|
87
107
|
|
|
88
108
|
Decision evaluation in `../decision/runtime.ts` uses the same session and recorder. It snapshots JSON input/questions
|
|
@@ -151,7 +151,7 @@ export class AiModelCallRecorder {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
/** Keep an unresolved reservation when an attempted call's billable outcome is unknown. */
|
|
154
|
-
|
|
154
|
+
async markCallUnknown(callId: string): Promise<void> {
|
|
155
155
|
if (!this.reservations.has(callId)) return
|
|
156
156
|
await this.input.limits.markModelCallUnknown({
|
|
157
157
|
projectId: this.input.projectId,
|