@cogenta/agents 0.1.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/dist/agents/define.d.ts +9 -0
- package/dist/agents/define.d.ts.map +1 -0
- package/dist/agents/define.js +25 -0
- package/dist/agents/define.js.map +1 -0
- package/dist/agents/registry.d.ts +29 -0
- package/dist/agents/registry.d.ts.map +1 -0
- package/dist/agents/registry.js +50 -0
- package/dist/agents/registry.js.map +1 -0
- package/dist/agents/types.d.ts +36 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +2 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/audit/types.d.ts +23 -0
- package/dist/audit/types.d.ts.map +1 -0
- package/dist/audit/types.js +2 -0
- package/dist/audit/types.js.map +1 -0
- package/dist/audit/with-audit.d.ts +34 -0
- package/dist/audit/with-audit.d.ts.map +1 -0
- package/dist/audit/with-audit.js +65 -0
- package/dist/audit/with-audit.js.map +1 -0
- package/dist/autonomy/approval-queue.d.ts +13 -0
- package/dist/autonomy/approval-queue.d.ts.map +1 -0
- package/dist/autonomy/approval-queue.js +56 -0
- package/dist/autonomy/approval-queue.js.map +1 -0
- package/dist/autonomy/types.d.ts +36 -0
- package/dist/autonomy/types.d.ts.map +1 -0
- package/dist/autonomy/types.js +2 -0
- package/dist/autonomy/types.js.map +1 -0
- package/dist/autonomy/with-autonomy.d.ts +25 -0
- package/dist/autonomy/with-autonomy.d.ts.map +1 -0
- package/dist/autonomy/with-autonomy.js +77 -0
- package/dist/autonomy/with-autonomy.js.map +1 -0
- package/dist/budget/kill-switch.d.ts +14 -0
- package/dist/budget/kill-switch.d.ts.map +1 -0
- package/dist/budget/kill-switch.js +20 -0
- package/dist/budget/kill-switch.js.map +1 -0
- package/dist/budget/tracker.d.ts +15 -0
- package/dist/budget/tracker.d.ts.map +1 -0
- package/dist/budget/tracker.js +68 -0
- package/dist/budget/tracker.js.map +1 -0
- package/dist/budget/types.d.ts +35 -0
- package/dist/budget/types.d.ts.map +1 -0
- package/dist/budget/types.js +2 -0
- package/dist/budget/types.js.map +1 -0
- package/dist/eval/assert-threshold.d.ts +15 -0
- package/dist/eval/assert-threshold.d.ts.map +1 -0
- package/dist/eval/assert-threshold.js +27 -0
- package/dist/eval/assert-threshold.js.map +1 -0
- package/dist/eval/compare-prompt-versions.d.ts +17 -0
- package/dist/eval/compare-prompt-versions.d.ts.map +1 -0
- package/dist/eval/compare-prompt-versions.js +20 -0
- package/dist/eval/compare-prompt-versions.js.map +1 -0
- package/dist/eval/run-suite.d.ts +4 -0
- package/dist/eval/run-suite.d.ts.map +1 -0
- package/dist/eval/run-suite.js +18 -0
- package/dist/eval/run-suite.js.map +1 -0
- package/dist/eval/scorers.d.ts +13 -0
- package/dist/eval/scorers.d.ts.map +1 -0
- package/dist/eval/scorers.js +33 -0
- package/dist/eval/scorers.js.map +1 -0
- package/dist/eval/types.d.ts +27 -0
- package/dist/eval/types.d.ts.map +1 -0
- package/dist/eval/types.js +2 -0
- package/dist/eval/types.js.map +1 -0
- package/dist/identity/constitution.d.ts +17 -0
- package/dist/identity/constitution.d.ts.map +1 -0
- package/dist/identity/constitution.js +33 -0
- package/dist/identity/constitution.js.map +1 -0
- package/dist/identity/context.d.ts +49 -0
- package/dist/identity/context.d.ts.map +1 -0
- package/dist/identity/context.js +67 -0
- package/dist/identity/context.js.map +1 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/file-store.d.ts +6 -0
- package/dist/memory/file-store.d.ts.map +1 -0
- package/dist/memory/file-store.js +94 -0
- package/dist/memory/file-store.js.map +1 -0
- package/dist/memory/from-approval.d.ts +20 -0
- package/dist/memory/from-approval.d.ts.map +1 -0
- package/dist/memory/from-approval.js +38 -0
- package/dist/memory/from-approval.js.map +1 -0
- package/dist/memory/memory-store.d.ts +4 -0
- package/dist/memory/memory-store.d.ts.map +1 -0
- package/dist/memory/memory-store.js +55 -0
- package/dist/memory/memory-store.js.map +1 -0
- package/dist/memory/types.d.ts +67 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +2 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/privacy/assert-provider-allowed.d.ts +10 -0
- package/dist/privacy/assert-provider-allowed.d.ts.map +1 -0
- package/dist/privacy/assert-provider-allowed.js +20 -0
- package/dist/privacy/assert-provider-allowed.js.map +1 -0
- package/dist/privacy/redact-fields.d.ts +11 -0
- package/dist/privacy/redact-fields.d.ts.map +1 -0
- package/dist/privacy/redact-fields.js +26 -0
- package/dist/privacy/redact-fields.js.map +1 -0
- package/dist/privacy/redact-text.d.ts +4 -0
- package/dist/privacy/redact-text.d.ts.map +1 -0
- package/dist/privacy/redact-text.js +26 -0
- package/dist/privacy/redact-text.js.map +1 -0
- package/dist/privacy/types.d.ts +23 -0
- package/dist/privacy/types.d.ts.map +1 -0
- package/dist/privacy/types.js +2 -0
- package/dist/privacy/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts +57 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +130 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/google.d.ts +63 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +144 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/openai.d.ts +56 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +143 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/registry.d.ts +31 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js +35 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/types.d.ts +63 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +10 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/rag/chunking/chunk-document.d.ts +13 -0
- package/dist/rag/chunking/chunk-document.d.ts.map +1 -0
- package/dist/rag/chunking/chunk-document.js +51 -0
- package/dist/rag/chunking/chunk-document.js.map +1 -0
- package/dist/rag/chunking/incremental.d.ts +19 -0
- package/dist/rag/chunking/incremental.d.ts.map +1 -0
- package/dist/rag/chunking/incremental.js +24 -0
- package/dist/rag/chunking/incremental.js.map +1 -0
- package/dist/rag/chunking/types.d.ts +34 -0
- package/dist/rag/chunking/types.d.ts.map +1 -0
- package/dist/rag/chunking/types.js +2 -0
- package/dist/rag/chunking/types.js.map +1 -0
- package/dist/rag/embeddings/hashing-provider.d.ts +22 -0
- package/dist/rag/embeddings/hashing-provider.d.ts.map +1 -0
- package/dist/rag/embeddings/hashing-provider.js +53 -0
- package/dist/rag/embeddings/hashing-provider.js.map +1 -0
- package/dist/rag/embeddings/types.d.ts +16 -0
- package/dist/rag/embeddings/types.d.ts.map +1 -0
- package/dist/rag/embeddings/types.js +2 -0
- package/dist/rag/embeddings/types.js.map +1 -0
- package/dist/rag/index/bm25.d.ts +4 -0
- package/dist/rag/index/bm25.d.ts.map +1 -0
- package/dist/rag/index/bm25.js +38 -0
- package/dist/rag/index/bm25.js.map +1 -0
- package/dist/rag/index/memory-index.d.ts +12 -0
- package/dist/rag/index/memory-index.d.ts.map +1 -0
- package/dist/rag/index/memory-index.js +44 -0
- package/dist/rag/index/memory-index.js.map +1 -0
- package/dist/rag/index/rrf.d.ts +9 -0
- package/dist/rag/index/rrf.d.ts.map +1 -0
- package/dist/rag/index/rrf.js +20 -0
- package/dist/rag/index/rrf.js.map +1 -0
- package/dist/rag/index/types.d.ts +48 -0
- package/dist/rag/index/types.d.ts.map +1 -0
- package/dist/rag/index/types.js +2 -0
- package/dist/rag/index/types.js.map +1 -0
- package/dist/rag/index/vector-rank.d.ts +4 -0
- package/dist/rag/index/vector-rank.d.ts.map +1 -0
- package/dist/rag/index/vector-rank.js +27 -0
- package/dist/rag/index/vector-rank.js.map +1 -0
- package/dist/reversibility/diff.d.ts +17 -0
- package/dist/reversibility/diff.d.ts.map +1 -0
- package/dist/reversibility/diff.js +39 -0
- package/dist/reversibility/diff.js.map +1 -0
- package/dist/reversibility/receipt-store.d.ts +9 -0
- package/dist/reversibility/receipt-store.d.ts.map +1 -0
- package/dist/reversibility/receipt-store.js +34 -0
- package/dist/reversibility/receipt-store.js.map +1 -0
- package/dist/reversibility/revert.d.ts +18 -0
- package/dist/reversibility/revert.d.ts.map +1 -0
- package/dist/reversibility/revert.js +38 -0
- package/dist/reversibility/revert.js.map +1 -0
- package/dist/reversibility/types.d.ts +25 -0
- package/dist/reversibility/types.d.ts.map +1 -0
- package/dist/reversibility/types.js +2 -0
- package/dist/reversibility/types.js.map +1 -0
- package/dist/reversibility/with-receipts.d.ts +19 -0
- package/dist/reversibility/with-receipts.d.ts.map +1 -0
- package/dist/reversibility/with-receipts.js +35 -0
- package/dist/reversibility/with-receipts.js.map +1 -0
- package/dist/runtime/loop.d.ts +11 -0
- package/dist/runtime/loop.d.ts.map +1 -0
- package/dist/runtime/loop.js +116 -0
- package/dist/runtime/loop.js.map +1 -0
- package/dist/runtime/repetition.d.ts +16 -0
- package/dist/runtime/repetition.d.ts.map +1 -0
- package/dist/runtime/repetition.js +38 -0
- package/dist/runtime/repetition.js.map +1 -0
- package/dist/runtime/retry.d.ts +22 -0
- package/dist/runtime/retry.d.ts.map +1 -0
- package/dist/runtime/retry.js +69 -0
- package/dist/runtime/retry.js.map +1 -0
- package/dist/runtime/types.d.ts +78 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/sandbox/types.d.ts +20 -0
- package/dist/sandbox/types.d.ts.map +1 -0
- package/dist/sandbox/types.js +2 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/sandbox/with-sandbox.d.ts +26 -0
- package/dist/sandbox/with-sandbox.d.ts.map +1 -0
- package/dist/sandbox/with-sandbox.js +41 -0
- package/dist/sandbox/with-sandbox.js.map +1 -0
- package/dist/skills/file-store.d.ts +13 -0
- package/dist/skills/file-store.d.ts.map +1 -0
- package/dist/skills/file-store.js +73 -0
- package/dist/skills/file-store.js.map +1 -0
- package/dist/skills/frontmatter.d.ts +11 -0
- package/dist/skills/frontmatter.d.ts.map +1 -0
- package/dist/skills/frontmatter.js +46 -0
- package/dist/skills/frontmatter.js.map +1 -0
- package/dist/skills/types.d.ts +19 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +2 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/skin/generate.d.ts +22 -0
- package/dist/skin/generate.d.ts.map +1 -0
- package/dist/skin/generate.js +144 -0
- package/dist/skin/generate.js.map +1 -0
- package/dist/subagents/run-subagent.d.ts +10 -0
- package/dist/subagents/run-subagent.d.ts.map +1 -0
- package/dist/subagents/run-subagent.js +24 -0
- package/dist/subagents/run-subagent.js.map +1 -0
- package/dist/subagents/types.d.ts +13 -0
- package/dist/subagents/types.d.ts.map +1 -0
- package/dist/subagents/types.js +2 -0
- package/dist/subagents/types.js.map +1 -0
- package/dist/subagents/validate.d.ts +8 -0
- package/dist/subagents/validate.d.ts.map +1 -0
- package/dist/subagents/validate.js +32 -0
- package/dist/subagents/validate.js.map +1 -0
- package/dist/tools/core/agent-delegate.d.ts +34 -0
- package/dist/tools/core/agent-delegate.d.ts.map +1 -0
- package/dist/tools/core/agent-delegate.js +41 -0
- package/dist/tools/core/agent-delegate.js.map +1 -0
- package/dist/tools/core/content.d.ts +81 -0
- package/dist/tools/core/content.d.ts.map +1 -0
- package/dist/tools/core/content.js +121 -0
- package/dist/tools/core/content.js.map +1 -0
- package/dist/tools/core/http-fetch.d.ts +33 -0
- package/dist/tools/core/http-fetch.d.ts.map +1 -0
- package/dist/tools/core/http-fetch.js +63 -0
- package/dist/tools/core/http-fetch.js.map +1 -0
- package/dist/tools/core/media.d.ts +38 -0
- package/dist/tools/core/media.d.ts.map +1 -0
- package/dist/tools/core/media.js +93 -0
- package/dist/tools/core/media.js.map +1 -0
- package/dist/tools/core/site-config.d.ts +19 -0
- package/dist/tools/core/site-config.d.ts.map +1 -0
- package/dist/tools/core/site-config.js +37 -0
- package/dist/tools/core/site-config.js.map +1 -0
- package/dist/tools/define.d.ts +12 -0
- package/dist/tools/define.d.ts.map +1 -0
- package/dist/tools/define.js +28 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/manifest.d.ts +19 -0
- package/dist/tools/manifest.d.ts.map +1 -0
- package/dist/tools/manifest.js +70 -0
- package/dist/tools/manifest.js.map +1 -0
- package/dist/tools/registry.d.ts +8 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +20 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +51 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/trace/capture.d.ts +19 -0
- package/dist/trace/capture.d.ts.map +1 -0
- package/dist/trace/capture.js +31 -0
- package/dist/trace/capture.js.map +1 -0
- package/dist/trace/file-store.d.ts +12 -0
- package/dist/trace/file-store.d.ts.map +1 -0
- package/dist/trace/file-store.js +78 -0
- package/dist/trace/file-store.js.map +1 -0
- package/dist/trace/memory-store.d.ts +9 -0
- package/dist/trace/memory-store.d.ts.map +1 -0
- package/dist/trace/memory-store.js +36 -0
- package/dist/trace/memory-store.js.map +1 -0
- package/dist/trace/types.d.ts +37 -0
- package/dist/trace/types.d.ts.map +1 -0
- package/dist/trace/types.js +2 -0
- package/dist/trace/types.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineTool } from '../define.js';
|
|
3
|
+
const DEFAULT_READ_OPTIONS = { state: 'working', depth: 0 };
|
|
4
|
+
function accessContextOf(actor) {
|
|
5
|
+
return { actor };
|
|
6
|
+
}
|
|
7
|
+
const EntrySchema = z.record(z.string(), z.unknown());
|
|
8
|
+
const ReadInputSchema = z.object({
|
|
9
|
+
collection: z.string(),
|
|
10
|
+
id: z.string(),
|
|
11
|
+
state: z.enum(['published', 'working']).optional(),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* `content.read` — the service is the actual permission gate (it calls
|
|
15
|
+
* `PermissionLayer.assert` internally against the collection's own
|
|
16
|
+
* `read`/`publish` roles); this tool only shapes the call and never
|
|
17
|
+
* second-guesses what the service decides.
|
|
18
|
+
*/
|
|
19
|
+
export function createContentReadTool(service) {
|
|
20
|
+
return defineTool({
|
|
21
|
+
name: 'content.read',
|
|
22
|
+
version: '1.0.0',
|
|
23
|
+
description: 'Read one content entry by collection and id.',
|
|
24
|
+
input: ReadInputSchema,
|
|
25
|
+
output: EntrySchema,
|
|
26
|
+
permissions: ['content.read'],
|
|
27
|
+
sideEffects: false,
|
|
28
|
+
reversible: false,
|
|
29
|
+
cost: 'low',
|
|
30
|
+
async execute(input, ctx) {
|
|
31
|
+
return service.read(accessContextOf(ctx.actor), input.collection, input.id, {
|
|
32
|
+
...DEFAULT_READ_OPTIONS,
|
|
33
|
+
...(input.state === undefined ? {} : { state: input.state }),
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const WriteDraftInputSchema = z.object({
|
|
39
|
+
collection: z.string(),
|
|
40
|
+
id: z.string().optional(),
|
|
41
|
+
values: z.record(z.string(), z.unknown()),
|
|
42
|
+
locale: z.string().optional(),
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* `content.write_draft` — creates a new working entry when `id` is absent,
|
|
46
|
+
* updates the existing one otherwise. Never touches the published state;
|
|
47
|
+
* that is `content.publish`'s job alone, matching `ContentService` keeping
|
|
48
|
+
* `create`/`update` and `publish` as distinct operations.
|
|
49
|
+
*/
|
|
50
|
+
export function createContentWriteDraftTool(service) {
|
|
51
|
+
return defineTool({
|
|
52
|
+
name: 'content.write_draft',
|
|
53
|
+
version: '1.0.0',
|
|
54
|
+
description: 'Create or update a working-state (draft) content entry.',
|
|
55
|
+
input: WriteDraftInputSchema,
|
|
56
|
+
output: EntrySchema,
|
|
57
|
+
permissions: ['content.write_draft'],
|
|
58
|
+
sideEffects: true,
|
|
59
|
+
// Not reversible through this tool: undoing a create means deleting the
|
|
60
|
+
// new entry, undoing an update means restoring a specific prior version
|
|
61
|
+
// (`ContentService.restore`, keyed by version number) — two different
|
|
62
|
+
// operations this wrapper cannot distinguish from the receipt alone
|
|
63
|
+
// without guessing. `reversible: false` forces human approval instead
|
|
64
|
+
// of a revert that might restore the wrong thing (R6).
|
|
65
|
+
reversible: false,
|
|
66
|
+
cost: 'low',
|
|
67
|
+
async execute(input, ctx) {
|
|
68
|
+
const context = accessContextOf(ctx.actor);
|
|
69
|
+
if (input.id !== undefined) {
|
|
70
|
+
return service.update(context, input.collection, input.id, { values: input.values }, DEFAULT_READ_OPTIONS);
|
|
71
|
+
}
|
|
72
|
+
return service.create(context, input.collection, { values: input.values, ...(input.locale === undefined ? {} : { locale: input.locale }) }, DEFAULT_READ_OPTIONS);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const PublishInputSchema = z.object({ collection: z.string(), id: z.string() });
|
|
77
|
+
export function createContentPublishTool(service) {
|
|
78
|
+
return defineTool({
|
|
79
|
+
name: 'content.publish',
|
|
80
|
+
version: '1.0.0',
|
|
81
|
+
description: 'Publish an existing content entry.',
|
|
82
|
+
input: PublishInputSchema,
|
|
83
|
+
output: EntrySchema,
|
|
84
|
+
permissions: ['content.publish'],
|
|
85
|
+
sideEffects: true,
|
|
86
|
+
// Not reversible through this tool: publishing again with the prior
|
|
87
|
+
// version's values is a distinct, explicit action (`content.write_draft`
|
|
88
|
+
// + `content.publish`), not an automatic undo — R6 requires either
|
|
89
|
+
// `revert` or `reversible: false` with forced human approval, and a
|
|
90
|
+
// silent "unpublish" here would be a surprising side effect of its own.
|
|
91
|
+
reversible: false,
|
|
92
|
+
cost: 'low',
|
|
93
|
+
rateLimit: { perHour: 20 },
|
|
94
|
+
async execute(input, ctx) {
|
|
95
|
+
return service.publish(accessContextOf(ctx.actor), input.collection, input.id, {}, DEFAULT_READ_OPTIONS);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const DeleteInputSchema = z.object({ collection: z.string(), id: z.string() });
|
|
100
|
+
const DeleteOutputSchema = z.object({ ok: z.boolean() });
|
|
101
|
+
export function createContentDeleteTool(service) {
|
|
102
|
+
return defineTool({
|
|
103
|
+
name: 'content.delete',
|
|
104
|
+
version: '1.0.0',
|
|
105
|
+
description: 'Delete a content entry.',
|
|
106
|
+
input: DeleteInputSchema,
|
|
107
|
+
output: DeleteOutputSchema,
|
|
108
|
+
permissions: ['content.delete'],
|
|
109
|
+
sideEffects: true,
|
|
110
|
+
// Deleting the row is not itself undoable from this tool's vantage
|
|
111
|
+
// point (the service, not this wrapper, owns whatever retention or
|
|
112
|
+
// trash mechanism it may have) — reversible: false forces approval.
|
|
113
|
+
reversible: false,
|
|
114
|
+
cost: 'low',
|
|
115
|
+
async execute(input, ctx) {
|
|
116
|
+
await service.remove(accessContextOf(ctx.actor), input.collection, input.id);
|
|
117
|
+
return { ok: true };
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../../src/tools/core/content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAmDzC,MAAM,oBAAoB,GAAuB,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;AAE/E,SAAS,eAAe,CAAC,KAGxB;IACC,OAAO,EAAE,KAAK,EAAE,CAAA;AAClB,CAAC;AAED,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC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C,gBAAgB,CAAC;QAC/B,WAAW,EAAE,IAAI;QACjB,mEAAmE;QACnE,mEAAmE;QACnE,oEAAoE;QACpE,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE,KAAK;QACX,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG;YACtB,MAAM,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,CAAA;YAC5E,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;QACrB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ToolDefinition } from '../types.js';
|
|
3
|
+
export interface HttpFetchToolOptions {
|
|
4
|
+
/** Exact hostnames this instance may reach — `http.fetch(domains[])` in the Contract C taxonomy is the permission this list backs. */
|
|
5
|
+
readonly allowedDomains: readonly string[];
|
|
6
|
+
readonly fetchImpl?: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
declare const HttpFetchInputSchema: z.ZodObject<{
|
|
9
|
+
url: z.ZodString;
|
|
10
|
+
method: z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
GET: "GET";
|
|
12
|
+
HEAD: "HEAD";
|
|
13
|
+
}>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type HttpFetchInput = z.infer<typeof HttpFetchInputSchema>;
|
|
16
|
+
declare const HttpFetchOutputSchema: z.ZodObject<{
|
|
17
|
+
status: z.ZodNumber;
|
|
18
|
+
headers: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
19
|
+
body: z.ZodString;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type HttpFetchOutput = z.infer<typeof HttpFetchOutputSchema>;
|
|
22
|
+
/**
|
|
23
|
+
* `http.fetch` — the domain allowlist is fixed at construction, one
|
|
24
|
+
* instance per agent's granted domains (how a `defineAgent` config's
|
|
25
|
+
* `http.fetch(domains: [...])` becomes this list is the runtime assembly's
|
|
26
|
+
* job, not this tool's). Restricted to `GET`/`HEAD`: a generic tool that can
|
|
27
|
+
* `POST` arbitrary bodies to arbitrary allowed hosts is a materially bigger
|
|
28
|
+
* blast radius than one that can only read, and nothing in L4's scope so
|
|
29
|
+
* far needs more than reading.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createHttpFetchTool(options: HttpFetchToolOptions): ToolDefinition<HttpFetchInput, HttpFetchOutput>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=http-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-fetch.d.ts","sourceRoot":"","sources":["../../../src/tools/core/http-fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,oBAAoB;IACnC,sIAAsI;IACtI,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;CAClC;AAED,QAAA,MAAM,oBAAoB;;;;;;iBAGxB,CAAA;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEjE,QAAA,MAAM,qBAAqB;;;;iBAIzB,CAAA;AACF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAA;AAEnE;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,cAAc,CAAC,cAAc,EAAE,eAAe,CAAC,CA0CjD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CogentaError } from '@cogenta/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { defineTool } from '../define.js';
|
|
4
|
+
const MAX_BODY_LENGTH = 100_000;
|
|
5
|
+
const HttpFetchInputSchema = z.object({
|
|
6
|
+
url: z.string(),
|
|
7
|
+
method: z.enum(['GET', 'HEAD']).optional(),
|
|
8
|
+
});
|
|
9
|
+
const HttpFetchOutputSchema = z.object({
|
|
10
|
+
status: z.number(),
|
|
11
|
+
headers: z.record(z.string(), z.string()),
|
|
12
|
+
body: z.string(),
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* `http.fetch` — the domain allowlist is fixed at construction, one
|
|
16
|
+
* instance per agent's granted domains (how a `defineAgent` config's
|
|
17
|
+
* `http.fetch(domains: [...])` becomes this list is the runtime assembly's
|
|
18
|
+
* job, not this tool's). Restricted to `GET`/`HEAD`: a generic tool that can
|
|
19
|
+
* `POST` arbitrary bodies to arbitrary allowed hosts is a materially bigger
|
|
20
|
+
* blast radius than one that can only read, and nothing in L4's scope so
|
|
21
|
+
* far needs more than reading.
|
|
22
|
+
*/
|
|
23
|
+
export function createHttpFetchTool(options) {
|
|
24
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
25
|
+
const allowed = new Set(options.allowedDomains);
|
|
26
|
+
return defineTool({
|
|
27
|
+
name: 'http.fetch',
|
|
28
|
+
version: '1.0.0',
|
|
29
|
+
description: 'Fetch a URL on an explicitly allowed domain (GET or HEAD only).',
|
|
30
|
+
input: HttpFetchInputSchema,
|
|
31
|
+
output: HttpFetchOutputSchema,
|
|
32
|
+
permissions: ['http.fetch'],
|
|
33
|
+
sideEffects: false,
|
|
34
|
+
reversible: false,
|
|
35
|
+
cost: 'low',
|
|
36
|
+
async execute(input, ctx) {
|
|
37
|
+
const parsed = new URL(input.url);
|
|
38
|
+
if (!allowed.has(parsed.hostname)) {
|
|
39
|
+
throw new CogentaError({
|
|
40
|
+
code: 'HTTP_FETCH_DOMAIN_DENIED',
|
|
41
|
+
message: `"${parsed.hostname}" is not in this agent's allowed domain list.`,
|
|
42
|
+
hint: 'Grant the domain in the agent definition, or fetch a different URL.',
|
|
43
|
+
details: { hostname: parsed.hostname, allowed: [...allowed] },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const response = await doFetch(parsed, {
|
|
47
|
+
method: input.method ?? 'GET',
|
|
48
|
+
signal: ctx.signal,
|
|
49
|
+
});
|
|
50
|
+
const text = await response.text();
|
|
51
|
+
const headers = {};
|
|
52
|
+
response.headers.forEach((value, key) => {
|
|
53
|
+
headers[key] = value;
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
status: response.status,
|
|
57
|
+
headers,
|
|
58
|
+
body: text.length > MAX_BODY_LENGTH ? `${text.slice(0, MAX_BODY_LENGTH)}…` : text,
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=http-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-fetch.js","sourceRoot":"","sources":["../../../src/tools/core/http-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzC,MAAM,eAAe,GAAG,OAAO,CAAA;AAQ/B,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAA;AAGF,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAA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,MAAM,OAAO,GAA2B,EAAE,CAAA;YAC1C,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBACtC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;YACtB,CAAC,CAAC,CAAA;YAEF,OAAO;gBACL,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,OAAO;gBACP,IAAI,EAAE,IAAI,CAAC,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI;aAClF,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MediaAsset, MediaStore } from '@cogenta/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ToolDefinition } from '../types.js';
|
|
4
|
+
declare const ReadInputSchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
type ReadInput = z.infer<typeof ReadInputSchema>;
|
|
8
|
+
/**
|
|
9
|
+
* `media.read` — `MediaStore` (`@cogenta/core`) has no permission layer of
|
|
10
|
+
* its own yet (`media-router.ts`'s own comment names this a known gap,
|
|
11
|
+
* closed here rather than there): this tool's declared `permissions` is the
|
|
12
|
+
* actual gate, enforced by the manifest before the call ever reaches the
|
|
13
|
+
* store.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createMediaReadTool(store: MediaStore): ToolDefinition<ReadInput, MediaAsset>;
|
|
16
|
+
declare const WriteInputSchema: z.ZodObject<{
|
|
17
|
+
id: z.ZodString;
|
|
18
|
+
alt: z.ZodOptional<z.ZodString>;
|
|
19
|
+
decorative: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
decorativeJustification: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
focal: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
22
|
+
x: z.ZodNumber;
|
|
23
|
+
y: z.ZodNumber;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
type WriteInput = z.infer<typeof WriteInputSchema>;
|
|
27
|
+
/**
|
|
28
|
+
* `media.write` — metadata only (alt text, decorative flag/justification,
|
|
29
|
+
* focal point). Uploading a new asset needs binary transfer this
|
|
30
|
+
* text/JSON tool-calling protocol was never designed to carry, and is a
|
|
31
|
+
* genuinely different, heavier operation (type sniffing, re-encoding,
|
|
32
|
+
* variant generation — `L2-admin.md`'s own media pipeline) than an agent
|
|
33
|
+
* editing an existing asset's accessibility metadata, which is the concrete
|
|
34
|
+
* use case this tool exists for (e.g. an accessibility-review agent).
|
|
35
|
+
*/
|
|
36
|
+
export declare function createMediaWriteTool(store: MediaStore): ToolDefinition<WriteInput, MediaAsset>;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../src/tools/core/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAoB,MAAM,eAAe,CAAA;AAE7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAqBjD,QAAA,MAAM,eAAe;;iBAA+B,CAAA;AACpD,KAAK,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AAEhD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,cAAc,CAAC,SAAS,EAAE,UAAU,CAAC,CAuB5F;AAED,QAAA,MAAM,gBAAgB;;;;;;;;;iBAMpB,CAAA;AACF,KAAK,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAElD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,EAAE,UAAU,CAAC,CAuB9F"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { CogentaError } from '@cogenta/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { defineTool } from '../define.js';
|
|
4
|
+
const FocalPointSchema = z.object({ x: z.number(), y: z.number() });
|
|
5
|
+
const MediaAssetSchema = z.object({
|
|
6
|
+
id: z.string(),
|
|
7
|
+
kind: z.enum(['image', 'video', 'audio', 'file']),
|
|
8
|
+
filename: z.string(),
|
|
9
|
+
mimeType: z.string(),
|
|
10
|
+
size: z.number(),
|
|
11
|
+
width: z.number().nullable(),
|
|
12
|
+
height: z.number().nullable(),
|
|
13
|
+
alt: z.string(),
|
|
14
|
+
decorative: z.boolean(),
|
|
15
|
+
decorativeJustification: z.string().nullable(),
|
|
16
|
+
focal: FocalPointSchema.nullable(),
|
|
17
|
+
storageKey: z.string(),
|
|
18
|
+
createdAt: z.string(),
|
|
19
|
+
createdBy: z.string().nullable(),
|
|
20
|
+
});
|
|
21
|
+
const ReadInputSchema = z.object({ id: z.string() });
|
|
22
|
+
/**
|
|
23
|
+
* `media.read` — `MediaStore` (`@cogenta/core`) has no permission layer of
|
|
24
|
+
* its own yet (`media-router.ts`'s own comment names this a known gap,
|
|
25
|
+
* closed here rather than there): this tool's declared `permissions` is the
|
|
26
|
+
* actual gate, enforced by the manifest before the call ever reaches the
|
|
27
|
+
* store.
|
|
28
|
+
*/
|
|
29
|
+
export function createMediaReadTool(store) {
|
|
30
|
+
return defineTool({
|
|
31
|
+
name: 'media.read',
|
|
32
|
+
version: '1.0.0',
|
|
33
|
+
description: 'Read one media asset by id.',
|
|
34
|
+
input: ReadInputSchema,
|
|
35
|
+
output: MediaAssetSchema,
|
|
36
|
+
permissions: ['media.read'],
|
|
37
|
+
sideEffects: false,
|
|
38
|
+
reversible: false,
|
|
39
|
+
cost: 'low',
|
|
40
|
+
async execute(input) {
|
|
41
|
+
const asset = await store.get(input.id);
|
|
42
|
+
if (asset === null) {
|
|
43
|
+
throw new CogentaError({
|
|
44
|
+
code: 'MEDIA_NOT_FOUND',
|
|
45
|
+
message: `No media asset with id "${input.id}".`,
|
|
46
|
+
hint: 'Check the id, or list media to find the right one.',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return asset;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const WriteInputSchema = z.object({
|
|
54
|
+
id: z.string(),
|
|
55
|
+
alt: z.string().optional(),
|
|
56
|
+
decorative: z.boolean().optional(),
|
|
57
|
+
decorativeJustification: z.string().nullable().optional(),
|
|
58
|
+
focal: FocalPointSchema.nullable().optional(),
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* `media.write` — metadata only (alt text, decorative flag/justification,
|
|
62
|
+
* focal point). Uploading a new asset needs binary transfer this
|
|
63
|
+
* text/JSON tool-calling protocol was never designed to carry, and is a
|
|
64
|
+
* genuinely different, heavier operation (type sniffing, re-encoding,
|
|
65
|
+
* variant generation — `L2-admin.md`'s own media pipeline) than an agent
|
|
66
|
+
* editing an existing asset's accessibility metadata, which is the concrete
|
|
67
|
+
* use case this tool exists for (e.g. an accessibility-review agent).
|
|
68
|
+
*/
|
|
69
|
+
export function createMediaWriteTool(store) {
|
|
70
|
+
return defineTool({
|
|
71
|
+
name: 'media.write',
|
|
72
|
+
version: '1.0.0',
|
|
73
|
+
description: "Update a media asset's alt text, decorative flag, or focal point.",
|
|
74
|
+
input: WriteInputSchema,
|
|
75
|
+
output: MediaAssetSchema,
|
|
76
|
+
permissions: ['media.write'],
|
|
77
|
+
sideEffects: true,
|
|
78
|
+
reversible: false,
|
|
79
|
+
cost: 'low',
|
|
80
|
+
async execute(input) {
|
|
81
|
+
const update = {
|
|
82
|
+
...(input.alt === undefined ? {} : { alt: input.alt }),
|
|
83
|
+
...(input.decorative === undefined ? {} : { decorative: input.decorative }),
|
|
84
|
+
...(input.decorativeJustification === undefined
|
|
85
|
+
? {}
|
|
86
|
+
: { decorativeJustification: input.decorativeJustification }),
|
|
87
|
+
...(input.focal === undefined ? {} : { focal: input.focal }),
|
|
88
|
+
};
|
|
89
|
+
return store.update(input.id, update);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../../src/tools/core/media.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAEnE,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACjD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE;IACvB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AM,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QACvC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ToolDefinition } from '../types.js';
|
|
3
|
+
declare const SiteConfigSchema: z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
url: z.ZodOptional<z.ZodString>;
|
|
6
|
+
locales: z.ZodArray<z.ZodString>;
|
|
7
|
+
defaultLocale: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export type SiteConfig = z.infer<typeof SiteConfigSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* `site.config_read` — a read-only projection of `ctx.site`, which the
|
|
12
|
+
* runtime already populates from `ResolvedConfig.site` (`@cogenta/core`).
|
|
13
|
+
* No `site.config_write` counterpart exists yet: the taxonomy names it, but
|
|
14
|
+
* writing site config from an agent needs its own review (which fields are
|
|
15
|
+
* even safe to let an agent touch) that is out of this task's scope.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSiteConfigReadTool(): ToolDefinition<Record<string, never>, SiteConfig>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=site-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-config.d.ts","sourceRoot":"","sources":["../../../src/tools/core/site-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,QAAA,MAAM,gBAAgB;;;;;iBAKpB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAEzD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,CAAC,CAoB5F"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineTool } from '../define.js';
|
|
3
|
+
const SiteConfigSchema = z.object({
|
|
4
|
+
name: z.string(),
|
|
5
|
+
url: z.string().optional(),
|
|
6
|
+
locales: z.array(z.string()),
|
|
7
|
+
defaultLocale: z.string(),
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* `site.config_read` — a read-only projection of `ctx.site`, which the
|
|
11
|
+
* runtime already populates from `ResolvedConfig.site` (`@cogenta/core`).
|
|
12
|
+
* No `site.config_write` counterpart exists yet: the taxonomy names it, but
|
|
13
|
+
* writing site config from an agent needs its own review (which fields are
|
|
14
|
+
* even safe to let an agent touch) that is out of this task's scope.
|
|
15
|
+
*/
|
|
16
|
+
export function createSiteConfigReadTool() {
|
|
17
|
+
return defineTool({
|
|
18
|
+
name: 'site.config_read',
|
|
19
|
+
version: '1.0.0',
|
|
20
|
+
description: "Read this site's configuration (name, url, locales).",
|
|
21
|
+
input: z.object({}),
|
|
22
|
+
output: SiteConfigSchema,
|
|
23
|
+
permissions: ['site.config_read'],
|
|
24
|
+
sideEffects: false,
|
|
25
|
+
reversible: false,
|
|
26
|
+
cost: 'low',
|
|
27
|
+
async execute(_input, ctx) {
|
|
28
|
+
return {
|
|
29
|
+
name: ctx.site.name,
|
|
30
|
+
...(ctx.site.url === undefined ? {} : { url: ctx.site.url }),
|
|
31
|
+
locales: [...ctx.site.locales],
|
|
32
|
+
defaultLocale: ctx.site.defaultLocale,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=site-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-config.js","sourceRoot":"","sources":["../../../src/tools/core/site-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1B,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC5B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAA;AAIF;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,sDAAsD;QACnE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;QACnB,MAAM,EAAE,gBAAgB;QACxB,WAAW,EAAE,CAAC,kBAAkB,CAAC;QACjC,WAAW,EAAE,KAAK;QAClB,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE,KAAK;QACX,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG;YACvB,OAAO;gBACL,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI;gBACnB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC5D,OAAO,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;gBAC9B,aAAa,EAAE,GAAG,CAAC,IAAI,CAAC,aAAa;aACtC,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ToolDefinition } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Structural validation of Contract C's two hard rules that a type alone
|
|
4
|
+
* cannot enforce: a `sideEffects: true` tool must be able to undo itself, and
|
|
5
|
+
* a tool must actually declare what it needs (an empty `permissions` array
|
|
6
|
+
* is either a mistake or a tool that should not exist — the registry has no
|
|
7
|
+
* way to gate an unpermissioned call, which defeats R4 before it starts).
|
|
8
|
+
* Returns the definition frozen, so nothing downstream can mutate a shared
|
|
9
|
+
* tool object between calls.
|
|
10
|
+
*/
|
|
11
|
+
export declare function defineTool<Input, Output>(definition: ToolDefinition<Input, Output>): ToolDefinition<Input, Output>;
|
|
12
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/tools/define.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EACtC,UAAU,EAAE,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,GACxC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAkB/B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CogentaError } from '@cogenta/core';
|
|
2
|
+
/**
|
|
3
|
+
* Structural validation of Contract C's two hard rules that a type alone
|
|
4
|
+
* cannot enforce: a `sideEffects: true` tool must be able to undo itself, and
|
|
5
|
+
* a tool must actually declare what it needs (an empty `permissions` array
|
|
6
|
+
* is either a mistake or a tool that should not exist — the registry has no
|
|
7
|
+
* way to gate an unpermissioned call, which defeats R4 before it starts).
|
|
8
|
+
* Returns the definition frozen, so nothing downstream can mutate a shared
|
|
9
|
+
* tool object between calls.
|
|
10
|
+
*/
|
|
11
|
+
export function defineTool(definition) {
|
|
12
|
+
if (definition.permissions.length === 0) {
|
|
13
|
+
throw new CogentaError({
|
|
14
|
+
code: 'TOOL_DEFINITION_INVALID',
|
|
15
|
+
message: `Tool "${definition.name}" declares no permissions.`,
|
|
16
|
+
hint: 'List at least one permission — an empty list cannot be gated by the tool registry.',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (definition.sideEffects && definition.reversible && definition.revert === undefined) {
|
|
20
|
+
throw new CogentaError({
|
|
21
|
+
code: 'TOOL_DEFINITION_INVALID',
|
|
22
|
+
message: `Tool "${definition.name}" declares sideEffects and reversible but implements no revert().`,
|
|
23
|
+
hint: 'Implement revert(), or set reversible: false so a human approves every call regardless of autonomy level.',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return Object.freeze(definition);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/tools/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAG5C;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,UAAyC;IAEzC,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,YAAY,CAAC;YACrB,IAAI,EAAE,yBAAyB;YAC/B,OAAO,EAAE,SAAS,UAAU,CAAC,IAAI,4BAA4B;YAC7D,IAAI,EAAE,oFAAoF;SAC3F,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACvF,MAAM,IAAI,YAAY,CAAC;YACrB,IAAI,EAAE,yBAAyB;YAC/B,OAAO,EAAE,SAAS,UAAU,CAAC,IAAI,mEAAmE;YACpG,IAAI,EAAE,2GAA2G;SAClH,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ExecutableTool } from '../runtime/types.js';
|
|
2
|
+
import type { ToolRegistry } from './registry.js';
|
|
3
|
+
import type { ToolContext } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* L4 task 4's actual enforcement point. "Un niveau inférieur ne peut jamais
|
|
6
|
+
* élargir les permissions d'un niveau supérieur" is not applied by the
|
|
7
|
+
* prompt — it is applied by never constructing an `ExecutableTool` for a
|
|
8
|
+
* name outside `allowedNames` in the first place. The model cannot ask its
|
|
9
|
+
* way into a tool that was never handed to `runAgentLoop`; a hallucinated or
|
|
10
|
+
* out-of-manifest call still resolves through the loop's own "no tool named
|
|
11
|
+
* X" path (task 2), which is the same refusal, from a different angle, for
|
|
12
|
+
* the same reason.
|
|
13
|
+
*
|
|
14
|
+
* `allowedNames` not found in `registry` fails immediately, at build time —
|
|
15
|
+
* the same "fail at load, not at call" posture task 11 uses for sub-agents,
|
|
16
|
+
* applied here to catch a misconfigured agent before it ever runs.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildManifest(registry: ToolRegistry, allowedNames: readonly string[], context: Omit<ToolContext, 'signal'>): readonly ExecutableTool[];
|
|
19
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/tools/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAA;AAE7D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,GACnC,SAAS,cAAc,EAAE,CAY3B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CogentaError } from '@cogenta/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* L4 task 4's actual enforcement point. "Un niveau inférieur ne peut jamais
|
|
5
|
+
* élargir les permissions d'un niveau supérieur" is not applied by the
|
|
6
|
+
* prompt — it is applied by never constructing an `ExecutableTool` for a
|
|
7
|
+
* name outside `allowedNames` in the first place. The model cannot ask its
|
|
8
|
+
* way into a tool that was never handed to `runAgentLoop`; a hallucinated or
|
|
9
|
+
* out-of-manifest call still resolves through the loop's own "no tool named
|
|
10
|
+
* X" path (task 2), which is the same refusal, from a different angle, for
|
|
11
|
+
* the same reason.
|
|
12
|
+
*
|
|
13
|
+
* `allowedNames` not found in `registry` fails immediately, at build time —
|
|
14
|
+
* the same "fail at load, not at call" posture task 11 uses for sub-agents,
|
|
15
|
+
* applied here to catch a misconfigured agent before it ever runs.
|
|
16
|
+
*/
|
|
17
|
+
export function buildManifest(registry, allowedNames, context) {
|
|
18
|
+
return allowedNames.map((name) => {
|
|
19
|
+
const tool = registry.get(name);
|
|
20
|
+
if (tool === undefined) {
|
|
21
|
+
throw new CogentaError({
|
|
22
|
+
code: 'TOOL_UNKNOWN',
|
|
23
|
+
message: `Agent manifest names "${name}", which no tool in the registry provides.`,
|
|
24
|
+
hint: 'Register the tool before building the manifest, or remove it from the agent definition.',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return toExecutableTool(tool, context);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function toExecutableTool(tool, context) {
|
|
31
|
+
return {
|
|
32
|
+
spec: {
|
|
33
|
+
name: tool.name,
|
|
34
|
+
description: tool.description,
|
|
35
|
+
inputSchema: z.toJSONSchema(tool.input),
|
|
36
|
+
},
|
|
37
|
+
sideEffects: tool.sideEffects,
|
|
38
|
+
reversible: tool.reversible,
|
|
39
|
+
async execute(input, execCtx) {
|
|
40
|
+
const parsedInput = tool.input.safeParse(input);
|
|
41
|
+
if (!parsedInput.success) {
|
|
42
|
+
throw new CogentaError({
|
|
43
|
+
code: 'TOOL_INPUT_INVALID',
|
|
44
|
+
message: `The input for "${tool.name}" did not match its declared schema.`,
|
|
45
|
+
hint: 'This is fed back to the model as a tool error, not thrown out of the run.',
|
|
46
|
+
details: { issues: parsedInput.error.issues },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const output = await tool.execute(parsedInput.data, { ...context, signal: execCtx.signal });
|
|
50
|
+
const parsedOutput = tool.output.safeParse(output);
|
|
51
|
+
if (!parsedOutput.success) {
|
|
52
|
+
throw new CogentaError({
|
|
53
|
+
code: 'TOOL_OUTPUT_INVALID',
|
|
54
|
+
message: `"${tool.name}" returned a value that did not match its declared output schema.`,
|
|
55
|
+
hint: 'This is a bug in the tool implementation, not in the caller.',
|
|
56
|
+
details: { issues: parsedOutput.error.issues },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return parsedOutput.data;
|
|
60
|
+
},
|
|
61
|
+
...(tool.revert === undefined
|
|
62
|
+
? {}
|
|
63
|
+
: {
|
|
64
|
+
async revert(receipt, execCtx) {
|
|
65
|
+
await tool.revert?.(receipt, { ...context, signal: execCtx.signal });
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/tools/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAKvB;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAsB,EACtB,YAA+B,EAC/B,OAAoC;IAEpC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC/B,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC/B,IAAI,IAAI,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I,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;gBAC1B,MAAM,IAAI,YAAY,CAAC;oBACrB,IAAI,EAAE,qBAAqB;oBAC3B,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,mEAAmE;oBACzF,IAAI,EAAE,8DAA8D;oBACpE,OAAO,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE;iBAC/C,CAAC,CAAA;YACJ,CAAC;YACD,OAAO,YAAY,CAAC,IAAI,CAAA;QAC1B,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS;YAC3B,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC;gBACE,KAAK,CAAC,MAAM,CAAC,OAAgB,EAAE,OAA6B;oBAC1D,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;gBACtE,CAAC;aACF,CAAC;KACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolDefinition } from './types.js';
|
|
2
|
+
export interface ToolRegistry {
|
|
3
|
+
list(): readonly ToolDefinition[];
|
|
4
|
+
get(name: string): ToolDefinition | undefined;
|
|
5
|
+
}
|
|
6
|
+
/** Every tool a site knows about — not what any one agent may call, that's the manifest (`buildManifest`) built on top of this. */
|
|
7
|
+
export declare function createToolRegistry(tools: readonly ToolDefinition[]): ToolRegistry;
|
|
8
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,SAAS,cAAc,EAAE,CAAA;IACjC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAAA;CAC9C;AAED,mIAAmI;AACnI,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,YAAY,CAiBjF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CogentaError } from '@cogenta/core';
|
|
2
|
+
/** Every tool a site knows about — not what any one agent may call, that's the manifest (`buildManifest`) built on top of this. */
|
|
3
|
+
export function createToolRegistry(tools) {
|
|
4
|
+
const byName = new Map();
|
|
5
|
+
for (const tool of tools) {
|
|
6
|
+
if (byName.has(tool.name)) {
|
|
7
|
+
throw new CogentaError({
|
|
8
|
+
code: 'TOOL_DUPLICATE',
|
|
9
|
+
message: `Two tools are registered under the name "${tool.name}".`,
|
|
10
|
+
hint: 'Tool names must be unique across the whole registry, core and third-party alike.',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
byName.set(tool.name, tool);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
list: () => [...byName.values()],
|
|
17
|
+
get: (name) => byName.get(name),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAQ5C,mIAAmI;AACnI,MAAM,UAAU,kBAAkB,CAAC,KAAgC;IACjE,MAAM,MAAM,GAAG,IAAI,GAAG,EAA0B,CAAA;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,YAAY,CAAC;gBACrB,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,4CAA4C,IAAI,CAAC,IAAI,IAAI;gBAClE,IAAI,EAAE,kFAAkF;aACzF,CAAC,CAAA;QACJ,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED,OAAO;QACL,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAChC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;KAChC,CAAA;AACH,CAAC"}
|