@sorbetai/plugins 0.0.0-stage → 0.1.0-alpha.16

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.
@@ -0,0 +1,16 @@
1
+ import { N as PluginInputSchema } from "./object-borrow-C81Gj5tq.js";
2
+ import * as s from "@earendil-works/pi-schema";
3
+
4
+ //#region src/contributions/run-yield.ts
5
+ const RunYieldMetadataProperties = {
6
+ contributionId: s.str({ minLength: 1 }),
7
+ behavior: s.opt(s.str({ minLength: 1 }))
8
+ };
9
+ const RunYieldMetadataSchema = s.obj(RunYieldMetadataProperties, { open: false });
10
+ const YieldDecisionSchema = s.union([s.obj({ continue: s.lit(false) }, { open: false }), s.obj({
11
+ continue: s.lit(true),
12
+ message: PluginInputSchema
13
+ }, { open: false })]);
14
+
15
+ //#endregion
16
+ export { RunYieldMetadataSchema as n, YieldDecisionSchema as r, RunYieldMetadataProperties as t };
@@ -0,0 +1,214 @@
1
+ import { Ct as PluginToolResult, E as YieldDecision, N as ObjectCatalog, O as PluginContextPreparationScope, S as CommittedAnswer, T as YieldContext, Y as PluginCompactionCompilerContribution, _t as ToolHookContext, bt as ToolHookFeedback, dn as SessionBehaviorMetadata, et as PluginCompactionObserverContribution, ft as PluginStateReadResult, gn as JsonValue, ht as PreparedToolHooks, j as ObjectAddress, l as PluginToolRegistration, mn as SessionBehaviorView, mt as PluginToolResultSnapshot, nt as PluginCompactionPolicyContribution, ot as PluginInput, pn as SessionBehaviorScope, sn as SessionBehaviorCommand, un as SessionBehaviorDispatch, vt as ToolHookContinuation, wt as ModelToolMetadataSchema, y as PluginToolExecutor } from "./context-i4UGSmNB.js";
2
+ import * as s from "@earendil-works/pi-schema";
3
+ import * as _sorbetai_schema93 from "@sorbetai/schema";
4
+ import { ContextHistorySnapshot, ContextModelView, ContextPreparationDraft, ContextPreparationResult, ToolDeclaration } from "@sorbetai/context";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Scope from "effect/Scope";
7
+
8
+ //#region src/model/object-capabilities.d.ts
9
+ interface ObjectCapabilityBinding {
10
+ readonly tool: PluginToolRegistration;
11
+ /** Retains this exact callback generation independently of the selection Scope.
12
+ * Closing the last borrow joins eligible cleanup; capture must not resolve a newer target. */
13
+ readonly borrow: Effect.Effect<void, Error, Scope.Scope>;
14
+ }
15
+ /** Borrowed Object capability access. Binding constructs the addressed instance and captures
16
+ * one method in the caller's Scope; it publishes no Platform Tool registration. */
17
+ interface ObjectCapabilitySource {
18
+ catalog(): Effect.Effect<ObjectCatalog, Error>;
19
+ bind(address: ObjectAddress, method: string, metadata: Pick<PluginToolRegistration, 'name' | 'description'>): Effect.Effect<ObjectCapabilityBinding, Error, Scope.Scope>;
20
+ }
21
+ interface ObjectCapabilityGrant {
22
+ readonly typeId: string;
23
+ readonly version: number;
24
+ readonly methods: readonly string[];
25
+ /** Optional additional restriction on keys; the registered key schema always applies. */
26
+ readonly keys?: s.Schema;
27
+ }
28
+ /** Explicit additional Session authority. This does not widen the Platform Plugin Tool ceiling
29
+ * and is not inherited by child Sessions. Methods remain held until explicit release,
30
+ * successful replacement, or Session close. */
31
+ interface ObjectCapabilityOptions {
32
+ /** Each namespace is bound to one borrowed source. Grants never cross source boundaries. */
33
+ readonly sources: readonly {
34
+ readonly namespace: string;
35
+ readonly source: ObjectCapabilitySource;
36
+ readonly grants: readonly ObjectCapabilityGrant[];
37
+ }[];
38
+ }
39
+ //#endregion
40
+ //#region src/model/view.d.ts
41
+ declare const ModelViewSchema: s.Schema<{
42
+ schemaVersion: 1;
43
+ tools: {
44
+ bindingId: string;
45
+ contributionId: string;
46
+ name: string;
47
+ description: string;
48
+ parameters: Record<string, _sorbetai_schema93.JsonValue>;
49
+ label?: string | undefined;
50
+ outputSchema?: Record<string, _sorbetai_schema93.JsonValue> | undefined;
51
+ discovery?: {
52
+ exposure?: "direct" | "deferred" | "hidden" | undefined;
53
+ namespace?: {
54
+ name: string;
55
+ description?: string | undefined;
56
+ } | undefined;
57
+ } | undefined;
58
+ metadata?: Record<string, _sorbetai_schema93.JsonValue> | undefined;
59
+ }[];
60
+ runYield?: {
61
+ bindingId: string;
62
+ contributionId: string;
63
+ entryId?: string | undefined;
64
+ activationId?: string | undefined;
65
+ behavior?: string | undefined;
66
+ }[] | undefined;
67
+ hooks?: {
68
+ contributionId: string;
69
+ version?: number | undefined;
70
+ before?: string[] | undefined;
71
+ after?: string[] | undefined;
72
+ }[] | undefined;
73
+ namedStates?: {
74
+ contributionId: string;
75
+ stateName: string;
76
+ schema: Record<string, _sorbetai_schema93.JsonValue>;
77
+ itemKey?: string | undefined;
78
+ }[] | undefined;
79
+ prefixes?: {
80
+ contributionId: string;
81
+ content: string;
82
+ }[] | undefined;
83
+ inputTransforms?: {
84
+ contributionId: string;
85
+ }[] | undefined;
86
+ preparationHooks?: {
87
+ hookId: string;
88
+ }[] | undefined;
89
+ sessionBehaviors?: {
90
+ contributionId: string;
91
+ name: string;
92
+ title: string;
93
+ stateSchema: Record<string, _sorbetai_schema93.JsonValue>;
94
+ initialState?: string | number | boolean | _sorbetai_schema93.JsonArray | _sorbetai_schema93.JsonObject | null | undefined;
95
+ initialView?: {
96
+ active: boolean;
97
+ contextState?: string | number | boolean | _sorbetai_schema93.JsonArray | _sorbetai_schema93.JsonObject | null | undefined;
98
+ constraints?: {
99
+ toolNames: string[];
100
+ workspace?: "read-only" | undefined;
101
+ } | undefined;
102
+ instructions?: string | undefined;
103
+ checklist?: {
104
+ content: string;
105
+ status: "pending" | "in_progress" | "completed";
106
+ }[] | undefined;
107
+ decision?: {
108
+ id: string;
109
+ title: string;
110
+ markdown: string;
111
+ choices: {
112
+ id: string;
113
+ title: string;
114
+ }[];
115
+ } | undefined;
116
+ continuation?: {
117
+ id: string;
118
+ prompt: string;
119
+ } | undefined;
120
+ } | undefined;
121
+ }[] | undefined;
122
+ historySelectors?: {
123
+ selectorId: string;
124
+ }[] | undefined;
125
+ }>;
126
+ type ModelView = Readonly<s.Static<typeof ModelViewSchema>>;
127
+ type ModelToolBinding = ModelView['tools'][number];
128
+ //#endregion
129
+ //#region src/model/source.d.ts
130
+ interface ModelToolLease extends AsyncDisposable {
131
+ yieldRun?(contributionId: string, answer: CommittedAnswer, context: YieldContext): Promise<YieldDecision>;
132
+ /** Recovery metadata is captured with callbacks, outside model-visible request evidence. */
133
+ toolRecovery?(bindingId: string): 'unsafe' | 'safe';
134
+ /** Uses this request's captured normalizer before schema validation and permission checks. */
135
+ prepareToolArguments?(bindingId: string, input: JsonValue): JsonValue;
136
+ /** Checks that this request borrow remains open, unexpired and uncancelled. Managed callbacks also check their current Package authorization. */
137
+ assertExecution(): void;
138
+ /** Filters complete history units in captured registration order, before preparation Hooks. */
139
+ selectHistory?(history: ContextHistorySnapshot, requestScopeId: string, signal?: AbortSignal): Promise<ContextModelView | undefined>;
140
+ /** Runs the captured callback chain; disposal joins all started downstream preparation. */
141
+ prepareContext?(draft: ContextPreparationDraft, scope: PluginContextPreparationScope): Promise<ContextPreparationResult>;
142
+ reduceBehavior?(name: string, state: JsonValue, command: SessionBehaviorCommand, scope: Omit<SessionBehaviorScope, 'sessionId'>): {
143
+ state: JsonValue;
144
+ view: SessionBehaviorView;
145
+ };
146
+ /** Cancels a review when this behavior registration or its resource dependency closure retires. */
147
+ behaviorSignal?(name: string): AbortSignal;
148
+ readonly leaseId: string;
149
+ readonly view: ModelView;
150
+ /** Explicit Host deadline, when configured; ordinary lifetime follows disposal. */
151
+ readonly deadline?: number;
152
+ readonly signal: AbortSignal;
153
+ transformInput?(input: PluginInput, source: JsonValue, mode?: 'initial' | 'steer' | 'followUp'): Promise<PluginInput>;
154
+ /** Reads only this request's captured state owner. */
155
+ readNamedState?(contributionId: string, signal?: AbortSignal, toolResults?: PluginToolResultSnapshot, toolCatalog?: readonly ToolDeclaration[]): Promise<PluginStateReadResult>;
156
+ prepareToolHooks?(input: JsonValue, context: Omit<ToolHookContext, 'sessionId' | 'runId'>): Promise<PreparedToolHooks>;
157
+ finishToolHooks?(prepared: PreparedToolHooks, result: ToolHookFeedback, context: Omit<ToolHookContext, 'sessionId' | 'runId'>): Promise<ToolHookFeedback>;
158
+ runToolHooks?(input: JsonValue, context: Omit<ToolHookContext, 'sessionId' | 'runId'>, continuation: ToolHookContinuation): Promise<ToolHookFeedback>;
159
+ /**
160
+ * The Session adapter must authorize and journal execution before invoking.
161
+ * toolCallId is the original model-protocol call identity, not the binding or Effect id.
162
+ * Callers that have no model call may omit it; individual contributions may require it.
163
+ * The optional observation provider must read committed feedback for this lease's
164
+ * Session without waiting for the executing Tool or its batch to settle.
165
+ */
166
+ invoke(bindingId: string, input: JsonValue, signal?: AbortSignal, toolCallId?: string, readToolResults?: (signal: AbortSignal) => Promise<PluginToolResultSnapshot>, commandBehavior?: SessionBehaviorDispatch, onUpdate?: (result: PluginToolResult) => void, traceContext?: {
167
+ readonly traceparent: string;
168
+ readonly tracestate?: string;
169
+ }, executeTool?: PluginToolExecutor, approval?: 'approved' | 'not-required', steeringSignal?: AbortSignal, toolCatalog?: readonly ToolDeclaration[]): Promise<PluginToolResult>;
170
+ }
171
+ /** Captured ownership is either a model Run or an explicit non-model operation. */
172
+ type ModelToolRequest = {
173
+ readonly sessionId: string;
174
+ readonly source?: JsonValue;
175
+ readonly signal: AbortSignal;
176
+ /** Optional absolute Host deadline; omission leaves this borrow owned by its Scope. */
177
+ readonly deadline?: number;
178
+ /** Filters executable Tool bindings and retained resources before capture. */
179
+ readonly toolNames?: readonly string[];
180
+ } & ({
181
+ readonly runId: string;
182
+ readonly operationId?: never;
183
+ } | {
184
+ readonly operationId: string;
185
+ readonly runId?: never;
186
+ });
187
+ type ModelToolMetadata = Readonly<s.Static<typeof ModelToolMetadataSchema>>;
188
+ type CommandToolDeclaration = ModelToolMetadata & {
189
+ readonly bindingId: string;
190
+ };
191
+ interface PluginCompactionSource {
192
+ readonly policy?: PluginCompactionPolicyContribution;
193
+ readonly compiler?: PluginCompactionCompilerContribution;
194
+ readonly observers?: readonly PluginCompactionObserverContribution[];
195
+ }
196
+ interface ModelToolSource {
197
+ /** Current committed command Tool declarations; reading does not acquire a lease. */
198
+ readonly commandTools?: readonly CommandToolDeclaration[];
199
+ /** Exactly one selected policy/compiler; absent when none is installed. */
200
+ readonly compaction?: PluginCompactionSource;
201
+ /** Synchronous invalidation after committed command Tools or Session behaviors change. */
202
+ subscribeCommands?(changed: () => void): () => void;
203
+ readonly tools?: readonly s.Static<typeof ModelToolMetadataSchema>[];
204
+ /** Current declarations for discovery only; commands still require an executable lease. */
205
+ readonly sessionBehaviors?: readonly SessionBehaviorMetadata[];
206
+ /** Synchronously captures callbacks and borrows their live owners; the borrower must dispose after all calls settle. */
207
+ acquire(input: ModelToolRequest): ModelToolLease;
208
+ }
209
+ /** Consumers borrow this port without owning Platform replacement or shutdown. */
210
+ interface PluginModelProvider {
211
+ readonly modelTools: ModelToolSource;
212
+ }
213
+ //#endregion
214
+ export { ModelToolSource as a, ModelView as c, ObjectCapabilityGrant as d, ObjectCapabilityOptions as f, ModelToolRequest as i, ModelViewSchema as l, ModelToolLease as n, PluginModelProvider as o, ObjectCapabilitySource as p, ModelToolMetadata as r, ModelToolBinding as s, CommandToolDeclaration as t, ObjectCapabilityBinding as u };
@@ -0,0 +1,73 @@
1
+ import { B as ModelToolMetadataProperties, E as PluginPrefixContributionSchema, I as SessionBehaviorMetadataSchema, M as InputTransformMetadataSchema, S as NamedStateMetadataSchema, d as ToolHookMetadataSchema, k as PreparationHookMetadataSchema } from "./object-borrow-C81Gj5tq.js";
2
+ import { t as RunYieldMetadataProperties } from "./run-yield-B1AE7-PN.js";
3
+ import * as s from "@earendil-works/pi-schema";
4
+ import { decode } from "@sorbetai/schema";
5
+ import * as Predicate from "effect/Predicate";
6
+
7
+ //#region src/contributions/history-selector.ts
8
+ const HistorySelectorMetadataSchema = s.obj({ selectorId: s.str({ minLength: 1 }) }, { open: false });
9
+ function captureHistorySelectorMetadata(selectors) {
10
+ const captured = selectors.map(({ selectorId }) => decode(HistorySelectorMetadataSchema, { selectorId }));
11
+ if (new Set(captured.map(({ selectorId }) => selectorId)).size !== captured.length) throw new TypeError("Duplicate Plugin history selector");
12
+ return captured;
13
+ }
14
+ async function runHistorySelectors(selectors, history, scope, signal) {
15
+ signal.throwIfAborted();
16
+ let selected = history.units;
17
+ for (const selector of selectors) {
18
+ const available = new Map(selected.map((unit, index) => [unit, index]));
19
+ const next = await selector.select({
20
+ ...scope,
21
+ history: {
22
+ ...history,
23
+ units: selected
24
+ },
25
+ signal
26
+ });
27
+ signal.throwIfAborted();
28
+ let previous = -1;
29
+ for (const unit of next) {
30
+ const index = available.get(unit);
31
+ if (index === void 0 || index <= previous) throw new TypeError("History selector must return an ordered subset of supplied units");
32
+ previous = index;
33
+ }
34
+ selected = next;
35
+ }
36
+ if (history.units.length === 0) return;
37
+ return {
38
+ throughSequence: history.throughSequence,
39
+ history: selected.flatMap((unit) => unit.messages.map(({ reference }) => reference))
40
+ };
41
+ }
42
+
43
+ //#endregion
44
+ //#region src/model/view.ts
45
+ const IdentitySchema = s.str({ minLength: 1 });
46
+ const ModelViewSchema = s.obj({
47
+ schemaVersion: s.lit(1),
48
+ runYield: s.opt(s.arr(s.obj({
49
+ ...RunYieldMetadataProperties,
50
+ bindingId: IdentitySchema,
51
+ entryId: s.opt(IdentitySchema),
52
+ activationId: s.opt(IdentitySchema)
53
+ }, { open: false }))),
54
+ hooks: s.opt(s.arr(ToolHookMetadataSchema)),
55
+ namedStates: s.opt(s.arr(NamedStateMetadataSchema)),
56
+ prefixes: s.opt(s.arr(PluginPrefixContributionSchema)),
57
+ inputTransforms: s.opt(s.arr(InputTransformMetadataSchema)),
58
+ preparationHooks: s.opt(s.arr(PreparationHookMetadataSchema)),
59
+ sessionBehaviors: s.opt(s.arr(SessionBehaviorMetadataSchema)),
60
+ historySelectors: s.opt(s.arr(HistorySelectorMetadataSchema)),
61
+ tools: s.arr(s.obj({
62
+ ...ModelToolMetadataProperties,
63
+ bindingId: IdentitySchema
64
+ }, { open: false }))
65
+ }, { open: false });
66
+ /** Immutable detached evidence is shared by captured requests and Journal projections. */
67
+ function freezeModelEvidence(value) {
68
+ Object.freeze(value);
69
+ for (const child of Object.values(value)) if (Predicate.isObjectOrArray(child) && !Object.isFrozen(child)) freezeModelEvidence(child);
70
+ }
71
+
72
+ //#endregion
73
+ export { runHistorySelectors as i, freezeModelEvidence as n, captureHistorySelectorMetadata as r, ModelViewSchema as t };
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@sorbetai/plugins",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-alpha.16",
4
+ "license": "MIT",
5
+ "description": "Effect-owned Plugin composition and request borrowing for Sorbet",
6
+ "type": "module",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./model": {
16
+ "types": "./dist/model.d.ts",
17
+ "import": "./dist/model.js"
18
+ },
19
+ "./remote": {
20
+ "types": "./dist/remote.d.ts",
21
+ "import": "./dist/remote.js"
22
+ },
23
+ "./node": {
24
+ "types": "./dist/node.d.ts",
25
+ "import": "./dist/node.js"
26
+ }
27
+ },
28
+ "dependencies": {
29
+ "acorn": "8.19.0",
30
+ "acorn-walk": "8.3.5",
31
+ "canonicalize": "5.1.0",
32
+ "effect": "4.1.0",
33
+ "ensure-error": "5.0.0",
34
+ "es-toolkit": "^1.53.1",
35
+ "@earendil-works/pi-schema": "1.5.0",
36
+ "@sorbetai/schema": "0.1.0-alpha.16",
37
+ "@sorbetai/context": "0.1.0-alpha.16"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^24.2.1",
41
+ "tsdown": "0.15.12",
42
+ "tsx": "^4.23.15",
43
+ "vitest": "^3.2.4"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/LodyAI/sorbet-distribution.git"
48
+ },
49
+ "scripts": {
50
+ "build": "tsdown",
51
+ "clean": "rm -rf dist coverage .turbo",
52
+ "dev": "tsdown --watch",
53
+ "test": "vitest run --maxWorkers=1",
54
+ "typecheck": "tsc --noEmit"
55
+ }
6
56
  }