@kindgi/agents 0.0.0-bootstrap.0 → 0.1.1
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/LICENSE +201 -0
- package/README.md +131 -2
- package/dist/agent-turn-flow.d.ts +57 -0
- package/dist/agent-turn-flow.d.ts.map +1 -0
- package/dist/agent-turn-flow.js +172 -0
- package/dist/agent-turn-flow.js.map +1 -0
- package/dist/conversation-binding.d.ts +111 -0
- package/dist/conversation-binding.d.ts.map +1 -0
- package/dist/conversation-binding.js +4 -0
- package/dist/conversation-binding.js.map +1 -0
- package/dist/define.d.ts +180 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +361 -0
- package/dist/define.js.map +1 -0
- package/dist/errors.d.ts +62 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -0
- package/dist/guardrails-gate.d.ts +169 -0
- package/dist/guardrails-gate.d.ts.map +1 -0
- package/dist/guardrails-gate.js +202 -0
- package/dist/guardrails-gate.js.map +1 -0
- package/dist/handlers/budget-check.d.ts +22 -0
- package/dist/handlers/budget-check.d.ts.map +1 -0
- package/dist/handlers/budget-check.js +109 -0
- package/dist/handlers/budget-check.js.map +1 -0
- package/dist/handlers/build-initial-messages.d.ts +17 -0
- package/dist/handlers/build-initial-messages.d.ts.map +1 -0
- package/dist/handlers/build-initial-messages.js +86 -0
- package/dist/handlers/build-initial-messages.js.map +1 -0
- package/dist/handlers/compose-result.d.ts +10 -0
- package/dist/handlers/compose-result.d.ts.map +1 -0
- package/dist/handlers/compose-result.js +79 -0
- package/dist/handlers/compose-result.js.map +1 -0
- package/dist/handlers/constants.d.ts +8 -0
- package/dist/handlers/constants.d.ts.map +1 -0
- package/dist/handlers/constants.js +10 -0
- package/dist/handlers/constants.js.map +1 -0
- package/dist/handlers/context.d.ts +210 -0
- package/dist/handlers/context.d.ts.map +1 -0
- package/dist/handlers/context.js +4 -0
- package/dist/handlers/context.js.map +1 -0
- package/dist/handlers/dispatch-tools.d.ts +15 -0
- package/dist/handlers/dispatch-tools.d.ts.map +1 -0
- package/dist/handlers/dispatch-tools.js +511 -0
- package/dist/handlers/dispatch-tools.js.map +1 -0
- package/dist/handlers/errors.d.ts +133 -0
- package/dist/handlers/errors.d.ts.map +1 -0
- package/dist/handlers/errors.js +134 -0
- package/dist/handlers/errors.js.map +1 -0
- package/dist/handlers/evaluate-guardrails.d.ts +14 -0
- package/dist/handlers/evaluate-guardrails.d.ts.map +1 -0
- package/dist/handlers/evaluate-guardrails.js +128 -0
- package/dist/handlers/evaluate-guardrails.js.map +1 -0
- package/dist/handlers/final-iteration.d.ts +7 -0
- package/dist/handlers/final-iteration.d.ts.map +1 -0
- package/dist/handlers/final-iteration.js +26 -0
- package/dist/handlers/final-iteration.js.map +1 -0
- package/dist/handlers/index.d.ts +5 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +41 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/model-call.d.ts +13 -0
- package/dist/handlers/model-call.d.ts.map +1 -0
- package/dist/handlers/model-call.js +136 -0
- package/dist/handlers/model-call.js.map +1 -0
- package/dist/handlers/persist-final-message.d.ts +14 -0
- package/dist/handlers/persist-final-message.d.ts.map +1 -0
- package/dist/handlers/persist-final-message.js +54 -0
- package/dist/handlers/persist-final-message.js.map +1 -0
- package/dist/handlers/persist-provenance.d.ts +12 -0
- package/dist/handlers/persist-provenance.d.ts.map +1 -0
- package/dist/handlers/persist-provenance.js +34 -0
- package/dist/handlers/persist-provenance.js.map +1 -0
- package/dist/handlers/persist-user-message.d.ts +15 -0
- package/dist/handlers/persist-user-message.d.ts.map +1 -0
- package/dist/handlers/persist-user-message.js +59 -0
- package/dist/handlers/persist-user-message.js.map +1 -0
- package/dist/handlers/public-types.d.ts +201 -0
- package/dist/handlers/public-types.d.ts.map +1 -0
- package/dist/handlers/public-types.js +4 -0
- package/dist/handlers/public-types.js.map +1 -0
- package/dist/handlers/rehydrate.d.ts +8 -0
- package/dist/handlers/rehydrate.d.ts.map +1 -0
- package/dist/handlers/rehydrate.js +94 -0
- package/dist/handlers/rehydrate.js.map +1 -0
- package/dist/handlers/render-prompt.d.ts +12 -0
- package/dist/handlers/render-prompt.d.ts.map +1 -0
- package/dist/handlers/render-prompt.js +41 -0
- package/dist/handlers/render-prompt.js.map +1 -0
- package/dist/handlers/resolve-tools.d.ts +10 -0
- package/dist/handlers/resolve-tools.d.ts.map +1 -0
- package/dist/handlers/resolve-tools.js +55 -0
- package/dist/handlers/resolve-tools.js.map +1 -0
- package/dist/handlers/result-shape.d.ts +94 -0
- package/dist/handlers/result-shape.d.ts.map +1 -0
- package/dist/handlers/result-shape.js +19 -0
- package/dist/handlers/result-shape.js.map +1 -0
- package/dist/handlers/run-retrievals.d.ts +10 -0
- package/dist/handlers/run-retrievals.d.ts.map +1 -0
- package/dist/handlers/run-retrievals.js +64 -0
- package/dist/handlers/run-retrievals.js.map +1 -0
- package/dist/handlers/run-snapshot.d.ts +4 -0
- package/dist/handlers/run-snapshot.d.ts.map +1 -0
- package/dist/handlers/run-snapshot.js +26 -0
- package/dist/handlers/run-snapshot.js.map +1 -0
- package/dist/handlers/setup.d.ts +25 -0
- package/dist/handlers/setup.d.ts.map +1 -0
- package/dist/handlers/setup.js +231 -0
- package/dist/handlers/setup.js.map +1 -0
- package/dist/handlers/structured-output.d.ts +38 -0
- package/dist/handlers/structured-output.d.ts.map +1 -0
- package/dist/handlers/structured-output.js +89 -0
- package/dist/handlers/structured-output.js.map +1 -0
- package/dist/handlers/tool-errors.d.ts +56 -0
- package/dist/handlers/tool-errors.d.ts.map +1 -0
- package/dist/handlers/tool-errors.js +73 -0
- package/dist/handlers/tool-errors.js.map +1 -0
- package/dist/handlers/tool-hitl.d.ts +45 -0
- package/dist/handlers/tool-hitl.d.ts.map +1 -0
- package/dist/handlers/tool-hitl.js +81 -0
- package/dist/handlers/tool-hitl.js.map +1 -0
- package/dist/handlers/turn-environment.d.ts +26 -0
- package/dist/handlers/turn-environment.d.ts.map +1 -0
- package/dist/handlers/turn-environment.js +154 -0
- package/dist/handlers/turn-environment.js.map +1 -0
- package/dist/hitl-policy.d.ts +45 -0
- package/dist/hitl-policy.d.ts.map +1 -0
- package/dist/hitl-policy.js +74 -0
- package/dist/hitl-policy.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/invoke.d.ts +36 -0
- package/dist/invoke.d.ts.map +1 -0
- package/dist/invoke.js +228 -0
- package/dist/invoke.js.map +1 -0
- package/dist/migrations-dir.d.ts +11 -0
- package/dist/migrations-dir.d.ts.map +1 -0
- package/dist/migrations-dir.js +14 -0
- package/dist/migrations-dir.js.map +1 -0
- package/dist/project-run-result.d.ts +23 -0
- package/dist/project-run-result.d.ts.map +1 -0
- package/dist/project-run-result.js +116 -0
- package/dist/project-run-result.js.map +1 -0
- package/dist/prompt.d.ts +83 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +119 -0
- package/dist/prompt.js.map +1 -0
- package/dist/provenance-emit.d.ts +44 -0
- package/dist/provenance-emit.d.ts.map +1 -0
- package/dist/provenance-emit.js +51 -0
- package/dist/provenance-emit.js.map +1 -0
- package/dist/registry.d.ts +38 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +125 -0
- package/dist/registry.js.map +1 -0
- package/dist/retrieval.d.ts +47 -0
- package/dist/retrieval.d.ts.map +1 -0
- package/dist/retrieval.js +155 -0
- package/dist/retrieval.js.map +1 -0
- package/dist/run-snapshot-binding.d.ts +77 -0
- package/dist/run-snapshot-binding.d.ts.map +1 -0
- package/dist/run-snapshot-binding.js +4 -0
- package/dist/run-snapshot-binding.js.map +1 -0
- package/dist/schema.d.ts +497 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +133 -0
- package/dist/schema.js.map +1 -0
- package/dist/streaming.d.ts +118 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +17 -0
- package/dist/streaming.js.map +1 -0
- package/dist/tenant-policy.d.ts +16 -0
- package/dist/tenant-policy.d.ts.map +1 -0
- package/dist/tenant-policy.js +77 -0
- package/dist/tenant-policy.js.map +1 -0
- package/dist/types.d.ts +435 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/versioning.d.ts +29 -0
- package/dist/versioning.d.ts.map +1 -0
- package/dist/versioning.js +58 -0
- package/dist/versioning.js.map +1 -0
- package/migrations/0000_sparkling_talkback.sql +18 -0
- package/migrations/0001_tired_warhawk.sql +16 -0
- package/migrations/0002_violet_ezekiel.sql +2 -0
- package/migrations/meta/0000_snapshot.json +172 -0
- package/migrations/meta/0001_snapshot.json +275 -0
- package/migrations/meta/0002_snapshot.json +287 -0
- package/migrations/meta/_journal.json +27 -0
- package/package.json +76 -4
- package/src/agent-turn-flow.ts +183 -0
- package/src/conversation-binding.ts +147 -0
- package/src/define.ts +572 -0
- package/src/errors.ts +80 -0
- package/src/guardrails-gate.ts +342 -0
- package/src/handlers/budget-check.ts +143 -0
- package/src/handlers/build-initial-messages.ts +103 -0
- package/src/handlers/compose-result.ts +90 -0
- package/src/handlers/constants.ts +10 -0
- package/src/handlers/context.ts +226 -0
- package/src/handlers/dispatch-tools.ts +633 -0
- package/src/handlers/errors.ts +282 -0
- package/src/handlers/evaluate-guardrails.ts +153 -0
- package/src/handlers/final-iteration.ts +30 -0
- package/src/handlers/index.ts +63 -0
- package/src/handlers/model-call.ts +151 -0
- package/src/handlers/persist-final-message.ts +67 -0
- package/src/handlers/persist-provenance.ts +39 -0
- package/src/handlers/persist-user-message.ts +70 -0
- package/src/handlers/public-types.ts +209 -0
- package/src/handlers/rehydrate.ts +161 -0
- package/src/handlers/render-prompt.ts +46 -0
- package/src/handlers/resolve-tools.ts +68 -0
- package/src/handlers/result-shape.ts +113 -0
- package/src/handlers/run-retrievals.ts +77 -0
- package/src/handlers/run-snapshot.ts +44 -0
- package/src/handlers/setup.ts +269 -0
- package/src/handlers/structured-output.ts +117 -0
- package/src/handlers/tool-errors.ts +122 -0
- package/src/handlers/tool-hitl.ts +126 -0
- package/src/handlers/turn-environment.ts +191 -0
- package/src/hitl-policy.ts +128 -0
- package/src/index.ts +154 -0
- package/src/invoke.ts +299 -0
- package/src/migrations-dir.ts +17 -0
- package/src/project-run-result.ts +131 -0
- package/src/prompt.ts +185 -0
- package/src/provenance-emit.ts +100 -0
- package/src/registry.ts +164 -0
- package/src/retrieval.ts +219 -0
- package/src/run-snapshot-binding.ts +87 -0
- package/src/schema.ts +154 -0
- package/src/streaming.ts +153 -0
- package/src/tenant-policy.ts +78 -0
- package/src/types.ts +453 -0
- package/src/versioning.ts +77 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import type { Capability } from '@kindgi/capabilities';
|
|
2
|
+
import type { Fact, MemoryScope } from '@kindgi/memory';
|
|
3
|
+
import type { ToolErrorsSpec, ToolHitlMode, ToolHitlRule } from '@kindgi/policy-contract';
|
|
4
|
+
import type { Brand, ConversationId, Semver, TenantId, Timestamp } from '@kindgi/types';
|
|
5
|
+
/**
|
|
6
|
+
* Branded agent id. Convention: dotted namespace under the tenant's
|
|
7
|
+
* pack — e.g. `acme.citation-verifier`, `acme.drafting`.
|
|
8
|
+
*/
|
|
9
|
+
export type AgentId = Brand<string, 'AgentId'>;
|
|
10
|
+
/**
|
|
11
|
+
* `ConversationId` lives in `@kindgi/types` (the single source of
|
|
12
|
+
* truth for branded identifiers) and is re-exported here for
|
|
13
|
+
* convenience; `@kindgi/types` (or `@kindgi/sdk/types`) is the
|
|
14
|
+
* canonical import.
|
|
15
|
+
*/
|
|
16
|
+
export type { ConversationId };
|
|
17
|
+
/**
|
|
18
|
+
* A single message inside a conversation. Persisted as a `Fact` in
|
|
19
|
+
* the memory subsystem scoped to the conversation, so it inherits
|
|
20
|
+
* retention + provenance + supersession from the fact substrate.
|
|
21
|
+
*
|
|
22
|
+
* The `role` discriminates who authored the message:
|
|
23
|
+
* - `user` — end-user input to the agent.
|
|
24
|
+
* - `agent` — the agent's assistant-role response.
|
|
25
|
+
* - `tool` — a tool-call result (the tool's own output).
|
|
26
|
+
* - `system` — a system-authored instruction (rare; e.g. HITL
|
|
27
|
+
* intervention, out-of-band context injection).
|
|
28
|
+
*/
|
|
29
|
+
export type MessageRole = 'user' | 'agent' | 'tool' | 'system';
|
|
30
|
+
export interface ConversationMessage {
|
|
31
|
+
/**
|
|
32
|
+
* Monotonic index within the conversation. Assigned by the writer.
|
|
33
|
+
* Combined with `conversationId` this gives a stable ordering
|
|
34
|
+
* independent of clock skew.
|
|
35
|
+
*/
|
|
36
|
+
readonly sequence: number;
|
|
37
|
+
readonly role: MessageRole;
|
|
38
|
+
/**
|
|
39
|
+
* Free-form text OR structured content. `string` is the common case
|
|
40
|
+
* (a chat message); `Record<string, unknown>` supports tool-result
|
|
41
|
+
* shapes and multi-modal payloads without a v2 bump.
|
|
42
|
+
*/
|
|
43
|
+
readonly content: string | Readonly<Record<string, unknown>>;
|
|
44
|
+
/**
|
|
45
|
+
* For `role: 'tool'` messages: the tool id and the invocation id
|
|
46
|
+
* that produced this output. Enables provenance edges from the
|
|
47
|
+
* originating agent turn to the tool's result.
|
|
48
|
+
*/
|
|
49
|
+
readonly toolCall?: {
|
|
50
|
+
readonly toolId: string;
|
|
51
|
+
readonly invocationId: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Attribution — user id, agent id, tool id, or system source. The
|
|
55
|
+
* literal role-vs-actor split lets the same agent produce many
|
|
56
|
+
* messages while the reviewer sees who was actually authoring.
|
|
57
|
+
*/
|
|
58
|
+
readonly actor?: string;
|
|
59
|
+
readonly createdAt: Timestamp;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A named, typed input to an agent's instructions template. Every
|
|
63
|
+
* `{{ var }}` referenced in `instructions` must correspond to either a
|
|
64
|
+
* declared `PromptParameter` OR a framework-supplied auto-variable
|
|
65
|
+
* (see `AUTO_INJECTED_VARS`).
|
|
66
|
+
*
|
|
67
|
+
* Types are declared so a UI can build a proper form for the caller
|
|
68
|
+
* ("enter firm name", "pick jurisdiction").
|
|
69
|
+
*/
|
|
70
|
+
export interface PromptParameter {
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly description?: string;
|
|
73
|
+
readonly type: 'string' | 'number' | 'boolean' | 'date';
|
|
74
|
+
/** Default true — omit to require the caller supply a value. */
|
|
75
|
+
readonly required?: boolean;
|
|
76
|
+
/** Default value used when the caller omits this parameter. */
|
|
77
|
+
readonly default?: string | number | boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Declarative statement of what the agent retrieves before each turn.
|
|
81
|
+
* Distinct from tool invocation — retrieval is background reading the
|
|
82
|
+
* agent does silently to ground its response.
|
|
83
|
+
*
|
|
84
|
+
* Scope options:
|
|
85
|
+
* - `same-conversation`: prior messages in this conversation only.
|
|
86
|
+
* - `same-project`: facts under the project (from Scope.projectId).
|
|
87
|
+
* - `tenant`: any tenant-scoped fact of the declared type.
|
|
88
|
+
*/
|
|
89
|
+
export interface RetrievalIntent {
|
|
90
|
+
readonly types: readonly string[];
|
|
91
|
+
readonly scope: 'same-conversation' | 'same-project' | 'tenant';
|
|
92
|
+
/** Cap on facts loaded per turn to keep the prompt small. Default 10. */
|
|
93
|
+
readonly limit?: number;
|
|
94
|
+
/** If `keyword` or `semantic`, biases which retrieval mode is used. */
|
|
95
|
+
readonly mode?: 'keyword' | 'semantic' | 'both';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Typed reference to a tool. Every agent tool binding is `{ id, version }`
|
|
99
|
+
* — no bare-id "latest" shortcut. `version` is a semver **range**
|
|
100
|
+
* (npm-style grammar), resolved at run start against the tenant's tool
|
|
101
|
+
* registry via `semver.maxSatisfying`.
|
|
102
|
+
*
|
|
103
|
+
* Range examples:
|
|
104
|
+
* - `'1.2.3'` — exact pin (matches only 1.2.3)
|
|
105
|
+
* - `'^1.2.3'` — compatible-updates (>=1.2.3 <2.0.0)
|
|
106
|
+
* - `'~1.2.3'` — patch-updates-only (>=1.2.3 <1.3.0)
|
|
107
|
+
* - `'>=1.0.0 <2.0.0'` — explicit range
|
|
108
|
+
*/
|
|
109
|
+
export interface ToolRef {
|
|
110
|
+
readonly id: string;
|
|
111
|
+
readonly version: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Per-agent behavior for multi-turn conversations. The agent chooses:
|
|
115
|
+
* - How many prior messages to load (`historyLimit`; unset = all).
|
|
116
|
+
* - Whether to auto-close a conversation after a period of inactivity
|
|
117
|
+
* (`autoCloseAfterInactiveSeconds` — checked at read time; unset =
|
|
118
|
+
* never auto-close).
|
|
119
|
+
* - A turn count after which each new turn waits for HITL approval
|
|
120
|
+
* before it runs (`hitlAfterTurns`; `hitl.afterTurns` takes
|
|
121
|
+
* precedence when both are set).
|
|
122
|
+
*/
|
|
123
|
+
export interface ConversationPolicy {
|
|
124
|
+
readonly historyLimit?: number;
|
|
125
|
+
readonly autoCloseAfterInactiveSeconds?: number;
|
|
126
|
+
readonly hitlAfterTurns?: number;
|
|
127
|
+
/**
|
|
128
|
+
* HITL policy: the session gate (`afterTurns`) and the tool-level
|
|
129
|
+
* gates that decide whether each tool call inside a turn waits for
|
|
130
|
+
* review before dispatch. Absent = no tool gates.
|
|
131
|
+
*/
|
|
132
|
+
readonly hitl?: ConversationHitlPolicy;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Tool-level HITL mode.
|
|
136
|
+
*
|
|
137
|
+
* - `never_ask` — dispatch straight through, no gate. Read-only tools
|
|
138
|
+
* (`Tool.mutating: false`) get this default.
|
|
139
|
+
* - `ask_on_first_use` — on the first call to `(toolId, hashOfArgs)`
|
|
140
|
+
* within a conversation, park + require approval. Approved decisions
|
|
141
|
+
* cache on the conversation so subsequent identical calls dispatch
|
|
142
|
+
* without re-parking. Mutating tools default to this.
|
|
143
|
+
* - `always_ask` — park + require approval on EVERY invocation. No
|
|
144
|
+
* caching. Highest friction; used for external-effect actions
|
|
145
|
+
* (email/payment/deploy) where every occurrence is a real event.
|
|
146
|
+
*/
|
|
147
|
+
/**
|
|
148
|
+
* A tool's gate (`never_ask` | `ask_on_first_use` | `always_ask`), and a
|
|
149
|
+
* per-tool rule — a mode plus the reviewer role its approvals need
|
|
150
|
+
* (deployments that route "always-ask-financial-tools" through senior
|
|
151
|
+
* reviewers use the rule; a mode alone routes through the agent's
|
|
152
|
+
* `defaultReviewerRole`). Shared with the tenant `hitl` policy, so they
|
|
153
|
+
* live in `@kindgi/policy-contract`.
|
|
154
|
+
*/
|
|
155
|
+
export type { ToolHitlMode, ToolHitlRule } from '@kindgi/policy-contract';
|
|
156
|
+
export interface ConversationHitlPolicy {
|
|
157
|
+
/**
|
|
158
|
+
* Session-turn count gate: once the conversation has this many
|
|
159
|
+
* completed turns, each new turn waits for HITL approval before it
|
|
160
|
+
* runs. Same meaning as `ConversationPolicy.hitlAfterTurns`; when both
|
|
161
|
+
* are set, `hitl.afterTurns` wins. Absent in both = no session gate.
|
|
162
|
+
*/
|
|
163
|
+
readonly afterTurns?: number;
|
|
164
|
+
/**
|
|
165
|
+
* Tool-level policy. Applies to every tool call inside the turn
|
|
166
|
+
* unless the `tools.overrides` map has a specific rule.
|
|
167
|
+
*/
|
|
168
|
+
readonly tools?: {
|
|
169
|
+
/**
|
|
170
|
+
* Mode for every tool without an entry in `overrides`. When absent,
|
|
171
|
+
* the framework falls back to a per-tool default: read-only tools
|
|
172
|
+
* (`mutating: false`) → `never_ask`, other tools →
|
|
173
|
+
* `ask_on_first_use`.
|
|
174
|
+
*/
|
|
175
|
+
readonly default?: ToolHitlMode;
|
|
176
|
+
/**
|
|
177
|
+
* Explicit overrides keyed by ToolId. A string value is shorthand
|
|
178
|
+
* for `{ mode: <string> }` — the required-role stays the agent
|
|
179
|
+
* default.
|
|
180
|
+
*/
|
|
181
|
+
readonly overrides?: Readonly<Record<string, ToolHitlMode | ToolHitlRule>>;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Reviewer role assigned to approvals materialized by tool + session
|
|
185
|
+
* gates. Absent = `'standard'`.
|
|
186
|
+
*/
|
|
187
|
+
readonly defaultReviewerRole?: 'standard' | 'senior' | 'admin';
|
|
188
|
+
/**
|
|
189
|
+
* Timeout the approval carries at enqueue time. Absent = the
|
|
190
|
+
* framework default (24h). A tenant policy's `maxTimeoutMs` caps it
|
|
191
|
+
* (see `resolveEffectiveHitlPolicy`).
|
|
192
|
+
*/
|
|
193
|
+
readonly timeoutMs?: number;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Budgets guard a single agent turn. Every field is optional; unset
|
|
197
|
+
* fields take the defaults below or have no cap. Steps and cost are
|
|
198
|
+
* enforced by the turn's `budget-check` step; wall-clock time by a
|
|
199
|
+
* timer in `invokeAgent`.
|
|
200
|
+
*/
|
|
201
|
+
export interface TurnBudget {
|
|
202
|
+
/** Maximum model→tool→model iterations per turn. Default 8. */
|
|
203
|
+
readonly maxSteps?: number;
|
|
204
|
+
/** Maximum USD spend per turn, summed over the turn's model calls. */
|
|
205
|
+
readonly maxCostUsd?: number;
|
|
206
|
+
/** Wall-clock cap in ms. Default 120_000 (2 min). */
|
|
207
|
+
readonly maxWallMs?: number;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* A typed result for an agent turn: the agent's final answer must be
|
|
211
|
+
* JSON matching `schema`. When it doesn't parse or doesn't match, the
|
|
212
|
+
* turn tells the model what was wrong and asks again, up to
|
|
213
|
+
* `maxRepairs` times; after that the turn fails with
|
|
214
|
+
* `output-schema-violation`. The parsed value is
|
|
215
|
+
* `AgentTurnResult.output`.
|
|
216
|
+
*/
|
|
217
|
+
export interface AgentOutputSpec {
|
|
218
|
+
/** JSON Schema (draft 2020-12) the final answer must match. */
|
|
219
|
+
readonly schema: Readonly<Record<string, unknown>>;
|
|
220
|
+
/** A name for the output (shown to the model and in errors). Default `'output'`. */
|
|
221
|
+
readonly name?: string;
|
|
222
|
+
/** How many times the model is asked to repair an invalid answer. Default 1. */
|
|
223
|
+
readonly maxRepairs?: number;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* An agent definition. Declarative: no runtime state, no closures. The
|
|
227
|
+
* same definition can be serialized, versioned, and reloaded — every
|
|
228
|
+
* field is either a primitive or a reference to a registered
|
|
229
|
+
* substrate object (tool id, guardrail id, capability declaration).
|
|
230
|
+
*
|
|
231
|
+
* The `version` field is authoritative for the agent's identity — an
|
|
232
|
+
* agent at a different version is a different agent for provenance
|
|
233
|
+
* and audit purposes. Callers pin agents by `{ id, version }` the way
|
|
234
|
+
* kernel runs pin flows.
|
|
235
|
+
*/
|
|
236
|
+
export interface Agent {
|
|
237
|
+
/**
|
|
238
|
+
* Globally-unique agent identifier. Convention:
|
|
239
|
+
* `<pack-id>.<agent-name>` (kebab-case, dot-namespaced). See the
|
|
240
|
+
* `AgentId` brand for the naming rule.
|
|
241
|
+
*/
|
|
242
|
+
readonly id: AgentId;
|
|
243
|
+
/**
|
|
244
|
+
* Semver — REQUIRED. Distinct from tools' `version` in that agents
|
|
245
|
+
* are versioned per-tenant (rotate + rollout independently of tool
|
|
246
|
+
* versions). `agent_conversations.agentVersion` pins each thread to
|
|
247
|
+
* a specific version; resume-across-version bumps rejects with
|
|
248
|
+
* `agent-version-mismatch`.
|
|
249
|
+
*/
|
|
250
|
+
readonly version: Semver;
|
|
251
|
+
/**
|
|
252
|
+
* Human-readable name shown in UI. Doesn't affect execution.
|
|
253
|
+
*/
|
|
254
|
+
readonly name: string;
|
|
255
|
+
/**
|
|
256
|
+
* Optional prose describing what the agent does. Shows up in the
|
|
257
|
+
* agent catalog and in provenance metadata.
|
|
258
|
+
*/
|
|
259
|
+
readonly description?: string;
|
|
260
|
+
/**
|
|
261
|
+
* System prompt rendered at the top of every turn. LiquidJS template
|
|
262
|
+
* syntax: `{{ variable }}` for substitution, `{% if %}` / `{% for %}`
|
|
263
|
+
* for control flow, filters via `{{ value | filter }}`. Every
|
|
264
|
+
* referenced variable must be either a declared `PromptParameter`
|
|
265
|
+
* or a framework-supplied auto-var (see `AUTO_INJECTED_VARS`).
|
|
266
|
+
*
|
|
267
|
+
* Templates are rendered with `strictVariables: true` — an
|
|
268
|
+
* unresolved reference fails the turn at invoke time
|
|
269
|
+
* (`model-invocation-failed` whose `cause` is the `missing-parameter`
|
|
270
|
+
* render error), never a silent empty string.
|
|
271
|
+
*/
|
|
272
|
+
readonly instructions: string;
|
|
273
|
+
/**
|
|
274
|
+
* Typed parameters the caller supplies at invoke time. The UI reads
|
|
275
|
+
* this to build a "configure agent" form; the runtime validates each
|
|
276
|
+
* required parameter is provided before the model call.
|
|
277
|
+
*
|
|
278
|
+
* Framework auto-vars (`today`, `now`, `agent.*`, `conversation.*`)
|
|
279
|
+
* do not need to be declared here — they're supplied by the runtime.
|
|
280
|
+
*/
|
|
281
|
+
readonly parameters?: readonly PromptParameter[];
|
|
282
|
+
/**
|
|
283
|
+
* Capability declarations the agent needs at runtime. Each entry is
|
|
284
|
+
* a separate resource-kind request (LLM inference, embedding, ...,
|
|
285
|
+
* distinguished by `Capability.kind`). The router picks providers at
|
|
286
|
+
* turn time; the agent definition doesn't hard-bind.
|
|
287
|
+
*
|
|
288
|
+
* The agent turn routes the first entry to pick its model; further
|
|
289
|
+
* entries are part of the definition but are not routed by the turn.
|
|
290
|
+
*/
|
|
291
|
+
readonly capabilities: readonly Capability[];
|
|
292
|
+
/**
|
|
293
|
+
* Typed tool references. Each entry declares the tool id AND the
|
|
294
|
+
* semver range (or exact pin) the agent expects to invoke — the
|
|
295
|
+
* dispatch resolver uses `semver.maxSatisfying` to pick the highest
|
|
296
|
+
* active version matching the range at run start. Follows the
|
|
297
|
+
* "docker-tag pin vs latest" discipline npm/docker take: no implicit
|
|
298
|
+
* `:latest`, ever.
|
|
299
|
+
*
|
|
300
|
+
* `version` is a semver **range** in the wire shape:
|
|
301
|
+
* `'1.2.3'` = exact pin, `'^1.2.3'` = compatible-updates, `'~1.2.3'`
|
|
302
|
+
* = patch-updates-only, `'>=1.0.0 <2.0.0'` = explicit range. Full
|
|
303
|
+
* npm-compatible grammar (grammar handled by the `semver` library
|
|
304
|
+
* in the resolver — validation of the range shape lives there).
|
|
305
|
+
*
|
|
306
|
+
* An empty list means the agent is chat-only.
|
|
307
|
+
*/
|
|
308
|
+
readonly tools: readonly ToolRef[];
|
|
309
|
+
/**
|
|
310
|
+
* Fact-retrieval intents. Zero or more; each triggers an independent
|
|
311
|
+
* retrieval pass before the model call.
|
|
312
|
+
*/
|
|
313
|
+
readonly retrieval: readonly RetrievalIntent[];
|
|
314
|
+
/**
|
|
315
|
+
* Guardrail ids the agent is subject to. Resolved at turn start
|
|
316
|
+
* against the guardrail definitions bound for the run
|
|
317
|
+
* (`GuardrailsBindings.guardrails`, evaluated through its `checks`
|
|
318
|
+
* registry from `@kindgi/guardrails`); an unknown id fails the turn
|
|
319
|
+
* with `unresolved-guardrail`. Evaluated once per turn, on the final
|
|
320
|
+
* response before it is stored.
|
|
321
|
+
*/
|
|
322
|
+
readonly guardrails: readonly string[];
|
|
323
|
+
/**
|
|
324
|
+
* Preferred model provider by id. Soft hint — the router prefers
|
|
325
|
+
* this provider when it satisfies the agent's `capabilities.needs`,
|
|
326
|
+
* falling back to normal capability-based selection when the
|
|
327
|
+
* preferred provider is unregistered or filtered out by tenant
|
|
328
|
+
* policy. Enables A/B'ing agents across providers without
|
|
329
|
+
* churning provider registrations: register several, pin the agent
|
|
330
|
+
* to the one you want to test.
|
|
331
|
+
*
|
|
332
|
+
* The value is a `ProviderMetadata.id` string (e.g. `'anthropic'`).
|
|
333
|
+
* Use in combination with `preferredModel` for `(provider, model)`
|
|
334
|
+
* tuple pinning. Unset = capability-match only.
|
|
335
|
+
*/
|
|
336
|
+
readonly preferredProvider?: string;
|
|
337
|
+
/**
|
|
338
|
+
* Preferred model NAME within the selected provider. Soft hint —
|
|
339
|
+
* the router prefers `(provider, model)` tuples matching this
|
|
340
|
+
* name, falling back to capability-based ranking when no tuple
|
|
341
|
+
* matches. Combined semantics with `preferredProvider`:
|
|
342
|
+
*
|
|
343
|
+
* - Both set → promote the exact `(provider, model)` tuple.
|
|
344
|
+
* - Only `preferredModel` set → promote any provider exposing
|
|
345
|
+
* that model.
|
|
346
|
+
* - Only `preferredProvider` set → any model of that provider is
|
|
347
|
+
* promoted.
|
|
348
|
+
*
|
|
349
|
+
* The value is a `ModelInfo.name` string (e.g. `'claude-sonnet-4-6'`).
|
|
350
|
+
* Enables model-level A/B'ing under one connection: register
|
|
351
|
+
* Anthropic once with `models: [sonnet, opus, haiku]`, then pin
|
|
352
|
+
* per-agent.
|
|
353
|
+
*/
|
|
354
|
+
readonly preferredModel?: string;
|
|
355
|
+
/**
|
|
356
|
+
* Multi-turn behavior. Optional — when unset, each turn loads the
|
|
357
|
+
* full conversation history and no HITL gates apply.
|
|
358
|
+
*/
|
|
359
|
+
readonly conversationPolicy?: ConversationPolicy;
|
|
360
|
+
/**
|
|
361
|
+
* Per-turn budget. Enforced by `invokeAgent`. Missing fields default
|
|
362
|
+
* (see `TurnBudget`).
|
|
363
|
+
*/
|
|
364
|
+
readonly budget?: TurnBudget;
|
|
365
|
+
/**
|
|
366
|
+
* Free-form tags for filtering in the agent catalog (UI + admin).
|
|
367
|
+
* Not consumed by execution.
|
|
368
|
+
*/
|
|
369
|
+
readonly tags?: readonly string[];
|
|
370
|
+
/**
|
|
371
|
+
* A typed result: the final answer is JSON matching this schema,
|
|
372
|
+
* validated (and repaired, see `AgentOutputSpec`) before the turn
|
|
373
|
+
* completes. Absent = the answer is free text.
|
|
374
|
+
*/
|
|
375
|
+
readonly output?: AgentOutputSpec;
|
|
376
|
+
/**
|
|
377
|
+
* What the turn does when a tool call fails: the failure goes back to
|
|
378
|
+
* the model as the call's result, so it can correct the call, up to
|
|
379
|
+
* `maxRetries` times per turn, for the kinds in `retryOn`. Default:
|
|
380
|
+
* one retry, for `invalid-arguments` and `unknown-tool` (nothing ran).
|
|
381
|
+
* A tenant's `tool-errors` policy can lower it. See `ToolErrorsSpec`.
|
|
382
|
+
*/
|
|
383
|
+
readonly toolErrors?: ToolErrorsSpec;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* A conversation record (the `agent_conversations` table in this
|
|
387
|
+
* package's Postgres schema). Messages are stored separately, as memory
|
|
388
|
+
* facts scoped to this conversation's id.
|
|
389
|
+
*/
|
|
390
|
+
export interface Conversation {
|
|
391
|
+
readonly id: ConversationId;
|
|
392
|
+
readonly tenantId: TenantId;
|
|
393
|
+
readonly agentId: AgentId;
|
|
394
|
+
readonly agentVersion: Semver;
|
|
395
|
+
/**
|
|
396
|
+
* Auto-generated on first turn or explicitly set. Shown in the UI
|
|
397
|
+
* conversation list.
|
|
398
|
+
*/
|
|
399
|
+
readonly title: string;
|
|
400
|
+
/** UUID or free-form identifier for the human participant. */
|
|
401
|
+
readonly participantId?: string;
|
|
402
|
+
/** Additional attributes (project id, matter id, etc.). */
|
|
403
|
+
readonly scope: MemoryScope;
|
|
404
|
+
readonly openedAt: Timestamp;
|
|
405
|
+
/** Set when the conversation is closed. Reopening is not supported. */
|
|
406
|
+
readonly closedAt?: Timestamp;
|
|
407
|
+
/**
|
|
408
|
+
* Denormalized turn counter — one +1 per completed agent turn.
|
|
409
|
+
* Incremented by the conversation binding when a turn's final
|
|
410
|
+
* (non-intermediate) agent message is appended.
|
|
411
|
+
*/
|
|
412
|
+
readonly turnCount: number;
|
|
413
|
+
readonly lastMessageAt?: Timestamp;
|
|
414
|
+
/**
|
|
415
|
+
* Free-form metadata. Persisted via the versioning envelope, so a
|
|
416
|
+
* schema change can be migrated on read.
|
|
417
|
+
*/
|
|
418
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Optional bindings for agent operations. Not read by `invokeAgent`,
|
|
422
|
+
* which takes `InvokeAgentBindings`.
|
|
423
|
+
*/
|
|
424
|
+
export interface AgentBindings {
|
|
425
|
+
/** A retrieval-policy registry from the memory implementation (untyped here). */
|
|
426
|
+
readonly memoryPolicyRegistry?: unknown;
|
|
427
|
+
}
|
|
428
|
+
/** A retrieved fact + the retrieval intent that pulled it. */
|
|
429
|
+
export interface RetrievedFact {
|
|
430
|
+
readonly fact: Fact<unknown>;
|
|
431
|
+
readonly intent: RetrievalIntent;
|
|
432
|
+
/** Similarity or keyword-rank score, if the retrieval mode produced one. */
|
|
433
|
+
readonly score?: number;
|
|
434
|
+
}
|
|
435
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAExF;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE/C;;;;;GAKG;AACH,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE/D,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B;;;;OAIG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ist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Result } from '@kindgi/types';
|
|
2
|
+
/**
|
|
3
|
+
* JSONB payload versioning for agents-owned tables. Nested
|
|
4
|
+
* `{ v: 1, doc: <content> }` envelope; `unwrap` accepts only
|
|
5
|
+
* `CURRENT_AGENTS_PAYLOAD_VERSION`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CURRENT_AGENTS_PAYLOAD_VERSION = 1;
|
|
8
|
+
export interface UnsupportedPayloadVersionError {
|
|
9
|
+
readonly code: 'unsupported-payload-version';
|
|
10
|
+
readonly message: string;
|
|
11
|
+
readonly version: number;
|
|
12
|
+
readonly currentVersion: number;
|
|
13
|
+
}
|
|
14
|
+
export interface MalformedEnvelopeError {
|
|
15
|
+
readonly code: 'malformed-envelope';
|
|
16
|
+
readonly message: string;
|
|
17
|
+
}
|
|
18
|
+
export type EnvelopeError = UnsupportedPayloadVersionError | MalformedEnvelopeError;
|
|
19
|
+
export declare class EnvelopeThrown extends Error {
|
|
20
|
+
readonly error: EnvelopeError;
|
|
21
|
+
constructor(error: EnvelopeError);
|
|
22
|
+
}
|
|
23
|
+
export declare function wrap<T>(value: T): {
|
|
24
|
+
readonly v: number;
|
|
25
|
+
readonly doc: T;
|
|
26
|
+
};
|
|
27
|
+
export declare function unwrap<T = unknown>(raw: unknown): Result<T | null | undefined, EnvelopeError>;
|
|
28
|
+
export declare function unwrapOrThrow<T = unknown>(raw: unknown): T | null | undefined;
|
|
29
|
+
//# sourceMappingURL=versioning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versioning.d.ts","sourceRoot":"","sources":["../src/versioning.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;GAIG;AAEH,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAEhD,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,IAAI,EAAE,6BAA6B,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,8BAA8B,GAAG,sBAAsB,CAAC;AAEpF,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;gBAClB,KAAK,EAAE,aAAa;CAKjC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAA;CAAE,CAEzE;AAED,wBAAgB,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,aAAa,CAAC,CA8B7F;AAED,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAI7E"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
/**
|
|
4
|
+
* JSONB payload versioning for agents-owned tables. Nested
|
|
5
|
+
* `{ v: 1, doc: <content> }` envelope; `unwrap` accepts only
|
|
6
|
+
* `CURRENT_AGENTS_PAYLOAD_VERSION`.
|
|
7
|
+
*/
|
|
8
|
+
export const CURRENT_AGENTS_PAYLOAD_VERSION = 1;
|
|
9
|
+
export class EnvelopeThrown extends Error {
|
|
10
|
+
error;
|
|
11
|
+
constructor(error) {
|
|
12
|
+
super(error.message);
|
|
13
|
+
this.error = error;
|
|
14
|
+
this.name = 'EnvelopeThrown';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function wrap(value) {
|
|
18
|
+
return { v: CURRENT_AGENTS_PAYLOAD_VERSION, doc: value };
|
|
19
|
+
}
|
|
20
|
+
export function unwrap(raw) {
|
|
21
|
+
if (raw === null || raw === undefined)
|
|
22
|
+
return { kind: 'ok', value: raw };
|
|
23
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
24
|
+
return {
|
|
25
|
+
kind: 'err',
|
|
26
|
+
error: {
|
|
27
|
+
code: 'malformed-envelope',
|
|
28
|
+
message: `Expected { v, doc } envelope, got ${typeof raw === 'object' ? 'array' : typeof raw}`,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const envelope = raw;
|
|
33
|
+
if (typeof envelope.v !== 'number' || !('doc' in envelope)) {
|
|
34
|
+
return {
|
|
35
|
+
kind: 'err',
|
|
36
|
+
error: { code: 'malformed-envelope', message: 'Payload is missing v or doc field' },
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (envelope.v === CURRENT_AGENTS_PAYLOAD_VERSION) {
|
|
40
|
+
return { kind: 'ok', value: envelope.doc };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
kind: 'err',
|
|
44
|
+
error: {
|
|
45
|
+
code: 'unsupported-payload-version',
|
|
46
|
+
message: `Unsupported payload version ${envelope.v} (this reader handles version ${CURRENT_AGENTS_PAYLOAD_VERSION})`,
|
|
47
|
+
version: envelope.v,
|
|
48
|
+
currentVersion: CURRENT_AGENTS_PAYLOAD_VERSION,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function unwrapOrThrow(raw) {
|
|
53
|
+
const r = unwrap(raw);
|
|
54
|
+
if (r.kind === 'err')
|
|
55
|
+
throw new EnvelopeThrown(r.error);
|
|
56
|
+
return r.value;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=versioning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versioning.js","sourceRoot":"","sources":["../src/versioning.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAIjC;;;;GAIG;AAEH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC;AAgBhD,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,KAAK,CAAgB;IAC9B,YAAY,KAAoB;QAC9B,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,IAAI,CAAI,KAAQ;IAC9B,OAAO,EAAE,CAAC,EAAE,8BAA8B,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,MAAM,CAAc,GAAY;IAC9C,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IACzE,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAClD,OAAO;YACL,IAAI,EAAE,KAAK;YACX,KAAK,EAAE;gBACL,IAAI,EAAE,oBAAoB;gBAC1B,OAAO,EAAE,qCAAqC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE;aAC/F;SACF,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,GAAuD,CAAC;IACzE,IAAI,OAAO,QAAQ,CAAC,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,QAAQ,CAAC,EAAE,CAAC;QAC3D,OAAO;YACL,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,mCAAmC,EAAE;SACpF,CAAC;IACJ,CAAC;IACD,IAAI,QAAQ,CAAC,CAAC,KAAK,8BAA8B,EAAE,CAAC;QAClD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAQ,EAAE,CAAC;IAClD,CAAC;IACD,OAAO;QACL,IAAI,EAAE,KAAK;QACX,KAAK,EAAE;YACL,IAAI,EAAE,6BAA6B;YACnC,OAAO,EAAE,+BAA+B,QAAQ,CAAC,CAAC,iCAAiC,8BAA8B,GAAG;YACpH,OAAO,EAAE,QAAQ,CAAC,CAAC;YACnB,cAAc,EAAE,8BAA8B;SAC/C;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAc,GAAY;IACrD,MAAM,CAAC,GAAG,MAAM,CAAI,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK;QAAE,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACxD,OAAO,CAAC,CAAC,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
CREATE TABLE "agent_conversations" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"tenant_id" uuid NOT NULL,
|
|
4
|
+
"agent_id" text NOT NULL,
|
|
5
|
+
"agent_version" text NOT NULL,
|
|
6
|
+
"title" text NOT NULL,
|
|
7
|
+
"participant_id" text,
|
|
8
|
+
"scope" jsonb NOT NULL,
|
|
9
|
+
"opened_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
10
|
+
"closed_at" timestamp with time zone,
|
|
11
|
+
"turn_count" integer DEFAULT 0 NOT NULL,
|
|
12
|
+
"last_message_at" timestamp with time zone,
|
|
13
|
+
"metadata" jsonb
|
|
14
|
+
);
|
|
15
|
+
--> statement-breakpoint
|
|
16
|
+
CREATE INDEX "agent_conversations_tenant_agent_idx" ON "agent_conversations" USING btree ("tenant_id","agent_id");--> statement-breakpoint
|
|
17
|
+
CREATE INDEX "agent_conversations_tenant_participant_idx" ON "agent_conversations" USING btree ("tenant_id","participant_id");--> statement-breakpoint
|
|
18
|
+
CREATE INDEX "agent_conversations_open_recent_idx" ON "agent_conversations" USING btree ("tenant_id","last_message_at" DESC NULLS LAST) WHERE "agent_conversations"."closed_at" IS NULL;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
CREATE TABLE "agent_run_snapshots" (
|
|
2
|
+
"id" uuid PRIMARY KEY NOT NULL,
|
|
3
|
+
"tenant_id" uuid NOT NULL,
|
|
4
|
+
"project_id" uuid NOT NULL,
|
|
5
|
+
"agent_id" text NOT NULL,
|
|
6
|
+
"agent_version" text NOT NULL,
|
|
7
|
+
"conversation_id" uuid NOT NULL,
|
|
8
|
+
"user_message" text NOT NULL,
|
|
9
|
+
"participant_id" text,
|
|
10
|
+
"dry_run" integer DEFAULT 0 NOT NULL,
|
|
11
|
+
"principal" jsonb,
|
|
12
|
+
"authz" jsonb,
|
|
13
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
14
|
+
);
|
|
15
|
+
--> statement-breakpoint
|
|
16
|
+
CREATE INDEX "agent_run_snapshots_tenant_idx" ON "agent_run_snapshots" USING btree ("tenant_id");
|