@popcomputer/structured-chat 0.1.0 → 0.2.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.
Files changed (50) hide show
  1. package/LICENSE +0 -1
  2. package/README.md +175 -108
  3. package/dist/adapters/openai-compatible-model.d.ts +4 -4
  4. package/dist/adapters/openai-compatible-model.js +33 -31
  5. package/dist/core/answer.d.ts +13 -13
  6. package/dist/core/answer.js +21 -12
  7. package/dist/core/chat.d.ts +12 -15
  8. package/dist/core/chat.js +36 -27
  9. package/dist/core/collect-stage.d.ts +28 -15
  10. package/dist/core/collect-stage.js +58 -37
  11. package/dist/core/command.d.ts +1 -1
  12. package/dist/core/command.js +1 -1
  13. package/dist/core/debug-protocol.d.ts +126 -0
  14. package/dist/core/debug-protocol.js +19 -0
  15. package/dist/core/debug.d.ts +103 -0
  16. package/dist/core/debug.js +276 -0
  17. package/dist/core/json-value.d.ts +1 -1
  18. package/dist/core/json-value.js +8 -1
  19. package/dist/core/model-guard.d.ts +2 -3
  20. package/dist/core/model-guard.js +4 -4
  21. package/dist/core/model.d.ts +15 -19
  22. package/dist/core/model.js +22 -10
  23. package/dist/core/protocol.d.ts +84 -79
  24. package/dist/core/protocol.js +18 -12
  25. package/dist/core/question.js +17 -15
  26. package/dist/core/repair.js +1 -1
  27. package/dist/core/session.d.ts +22 -28
  28. package/dist/core/session.js +16 -7
  29. package/dist/core/stage-name.d.ts +1 -1
  30. package/dist/core/stage-name.js +1 -1
  31. package/dist/core/stage.d.ts +4 -4
  32. package/dist/core/stage.js +11 -8
  33. package/dist/core/tool-set.js +6 -6
  34. package/dist/core/tool.d.ts +36 -39
  35. package/dist/core/tool.js +58 -31
  36. package/dist/core/view.d.ts +64 -39
  37. package/dist/core/view.js +12 -15
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +2 -0
  40. package/dist/integrations/assistant-ui-debug.d.ts +25 -0
  41. package/dist/integrations/assistant-ui-debug.js +1162 -0
  42. package/dist/integrations/assistant-ui.d.ts +10 -3
  43. package/dist/integrations/assistant-ui.js +48 -18
  44. package/dist/testing/in-memory-session-store.js +1 -1
  45. package/dist/testing/scenario.js +6 -6
  46. package/examples/answer-modes.ts +60 -49
  47. package/examples/prompt-injection-policy.ts +20 -20
  48. package/examples/resource-search.ts +104 -0
  49. package/package.json +15 -3
  50. package/examples/agency-search.ts +0 -101
@@ -1,4 +1,4 @@
1
- import { Effect, Schema, unsafeCoerce } from "effect";
1
+ import { Effect, Function as Fn, Schema } from "effect";
2
2
  import { Instruction, planToolCall, StructuredChatModel, } from "./model.js";
3
3
  import { defineToolSet, } from "./tool-set.js";
4
4
  import { defineCollectStage } from "./collect-stage.js";
@@ -6,7 +6,10 @@ import { StageNameSchema } from "./stage-name.js";
6
6
  import { structuredDefinition, } from "./definition.js";
7
7
  export { StageNameSchema } from "./stage-name.js";
8
8
  /** State transition applied after one tool-stage execution. */
9
- export const ToolStageAfterExecutionSchema = Schema.Literal("stay", "complete");
9
+ export const ToolStageAfterExecutionSchema = Schema.Literals([
10
+ "stay",
11
+ "complete",
12
+ ]);
10
13
  const toolStageRuntime = Symbol("@popcomputer/structured-chat/ToolStageRuntime");
11
14
  /** @internal Read the erased runtime from an authentic tool stage. */
12
15
  export const readToolStageRuntime = (stage) => stage[toolStageRuntime];
@@ -19,7 +22,7 @@ const defineToolStage = (definition) => {
19
22
  const toolSet = defineToolSet(...definition.tools);
20
23
  // SAFETY: when guards are omitted, Guards uses its readonly [] default; an
21
24
  // explicitly supplied tuple is returned unchanged.
22
- const guards = definition.guards ?? unsafeCoerce([]);
25
+ const guards = definition.guards ?? Fn.cast([]);
23
26
  const afterExecution = Schema.decodeSync(ToolStageAfterExecutionSchema)(definition.afterExecution ?? "stay");
24
27
  const plan = (messages) => planToolCall({
25
28
  instructions,
@@ -32,7 +35,7 @@ const defineToolStage = (definition) => {
32
35
  const run = (messages) => plan(messages).pipe(Effect.flatMap(toolSet.execute));
33
36
  // SAFETY: chat repair supplies only a call parsed by a combined set that
34
37
  // contains this exact query tuple; non-repair names therefore belong here.
35
- const executeRuntime = toolSet.execute;
38
+ const executeRuntime = Fn.cast(toolSet.execute);
36
39
  const planWith = (messages, additionalTool) => {
37
40
  // SAFETY: the additional package-owned query and this non-empty exact
38
41
  // query tuple form another valid closed tool set for planning only.
@@ -65,24 +68,24 @@ const defineCommandStage = (definition) => {
65
68
  Schema.decodeSync(StageNameSchema)(definition.name);
66
69
  const instructions = definition.instructions.map(Instruction.make);
67
70
  // SAFETY: when omitted, Guards is its readonly [] default.
68
- const guards = definition.guards ?? unsafeCoerce([]);
71
+ const guards = definition.guards ?? Fn.cast([]);
69
72
  const planner = {
70
73
  models: [definition.command.model],
71
74
  // SAFETY: this command parses its literal name and exact input schema.
72
- parseCall: definition.command.parseCall,
75
+ parseCall: Fn.cast(definition.command.parseCall),
73
76
  };
74
77
  const plan = (messages) => planToolCall({ instructions, messages, tools: planner, guards }).pipe(Effect.withSpan("popcomputer.structured_chat.command_stage.plan", {
75
78
  attributes: { stage: definition.name },
76
79
  }));
77
80
  // SAFETY: Command has the package-owned identity and command operation;
78
81
  // its parsed call and runtime execute input originate from one definition.
79
- const runtimeCommand = unsafeCoerce(definition.command);
82
+ const runtimeCommand = Fn.cast(definition.command);
80
83
  const runRuntime = (messages, context) => plan(messages).pipe(Effect.flatMap((call) => runtimeCommand.execute(call.arguments, context)), Effect.withSpan("popcomputer.structured_chat.command_stage.run", {
81
84
  attributes: { stage: definition.name },
82
85
  }));
83
86
  // SAFETY: failures and requirements are not recovered; the command's
84
87
  // projections and result are preserved by its own execute operation.
85
- const run = runRuntime;
88
+ const run = Fn.cast(runRuntime);
86
89
  return structuredDefinition("command_stage")({
87
90
  _tag: "CommandStage",
88
91
  name: definition.name,
@@ -1,4 +1,4 @@
1
- import { Effect, Schema, unsafeCoerce } from "effect";
1
+ import { Effect, Function as Fn, Schema } from "effect";
2
2
  import { InvalidToolCall as InvalidToolCallError, InvalidToolCallReasonSchema, ToolNameSchema, } from "./tool.js";
3
3
  import { JsonValueSchema } from "./json-value.js";
4
4
  const IncomingToolCallSchema = Schema.Struct({
@@ -28,7 +28,7 @@ export const defineToolSet = (...tools) => {
28
28
  // SAFETY: ToolDefinitionContract carries the package-owned nominal identity.
29
29
  // Runtime execution is erased here and restored by ToolSet's conditional
30
30
  // public result, error, and requirement types.
31
- runtimeTools.set(tool.name, unsafeCoerce(tool));
31
+ runtimeTools.set(tool.name, Fn.cast(tool));
32
32
  }
33
33
  const selectTool = (name) => {
34
34
  const tool = runtimeTools.get(name);
@@ -37,21 +37,21 @@ export const defineToolSet = (...tools) => {
37
37
  }
38
38
  return Effect.succeed(tool);
39
39
  };
40
- const parseCallRuntime = (input) => Schema.decodeUnknown(IncomingToolCallSchema)(input, {
40
+ const parseCallRuntime = (input) => Schema.decodeUnknownEffect(IncomingToolCallSchema)(input, {
41
41
  onExcessProperty: "error",
42
42
  }).pipe(Effect.mapError(() => invalidCall("invalid_envelope", null)), Effect.flatMap((call) => selectTool(call.name).pipe(Effect.flatMap((tool) => tool.parseCall(call)))), Effect.withSpan("popcomputer.structured_chat.tool_set.parse", {
43
43
  attributes: { toolCount: tools.length },
44
44
  }));
45
45
  // SAFETY: the envelope parser establishes a registered name, then that
46
46
  // registered tool parses its own literal name and argument schema.
47
- const parseCall = parseCallRuntime;
47
+ const parseCall = Fn.cast(parseCallRuntime);
48
48
  const executeRuntime = (call) => selectTool(call.name).pipe(Effect.flatMap((tool) => tool.execute(call.arguments)), Effect.withSpan("popcomputer.structured_chat.tool_set.execute", {
49
49
  attributes: { toolCount: tools.length },
50
50
  }));
51
51
  // SAFETY: call is a parsed member of ToolSetCall<Tools>; dispatch selects
52
52
  // that member's registered runtime and passes its decoded arguments to the
53
53
  // corresponding Type-side execute operation.
54
- const execute = executeRuntime;
54
+ const execute = Fn.cast(executeRuntime);
55
55
  const executeCall = (input) => parseCall(input).pipe(Effect.flatMap(execute));
56
56
  return {
57
57
  tools,
@@ -61,6 +61,6 @@ export const defineToolSet = (...tools) => {
61
61
  // SAFETY: dispatch selects a member of Tools by its unique runtime name.
62
62
  // Each tool parses itself before executing, so the resulting union exactly
63
63
  // matches ToolSetExecution, ToolSetError, and ToolSetRequirements.
64
- executeCall: executeCall,
64
+ executeCall: Fn.cast(executeCall),
65
65
  };
66
66
  };
@@ -1,34 +1,29 @@
1
- import { Effect, JSONSchema, Pipeable, Schema } from "effect";
2
- import * as ParseResult from "effect/ParseResult";
1
+ import { Effect, JsonSchema, Pipeable, Schema } from "effect";
3
2
  import type { ViewDefinitionContract, ViewInput, ViewPart } from "./view.js";
4
3
  import { type StructuredDefinition } from "./definition.js";
5
4
  import type { CommandId } from "./command.js";
6
5
  import type { JsonValue } from "./json-value.js";
7
6
  /** Stable machine-facing name for one structured chat tool. */
8
- export declare const ToolNameSchema: Schema.filter<Schema.filter<typeof Schema.NonEmptyTrimmedString>>;
7
+ export declare const ToolNameSchema: Schema.Trimmed;
9
8
  /** Bounded model-facing description for one structured chat tool. */
10
- export declare const ToolDescriptionSchema: Schema.filter<typeof Schema.NonEmptyTrimmedString>;
9
+ export declare const ToolDescriptionSchema: Schema.Trimmed;
11
10
  /** Safe reason that a model-authored tool call was rejected. */
12
- export declare const InvalidToolCallReasonSchema: Schema.Literal<["invalid_envelope", "unknown_tool", "invalid_arguments"]>;
13
- declare const InvalidToolCall_base: Schema.TaggedErrorClass<InvalidToolCall, "InvalidToolCall", {
14
- readonly _tag: Schema.tag<"InvalidToolCall">;
15
- } & {
16
- tool: Schema.NullOr<Schema.filter<Schema.filter<typeof Schema.NonEmptyTrimmedString>>>;
17
- reason: Schema.Literal<["invalid_envelope", "unknown_tool", "invalid_arguments"]>;
18
- path: Schema.NullOr<Schema.filter<typeof Schema.NonEmptyTrimmedString>>;
19
- }>;
11
+ export declare const InvalidToolCallReasonSchema: Schema.Literals<readonly ["invalid_envelope", "unknown_tool", "invalid_arguments"]>;
12
+ declare const InvalidToolCall_base: Schema.Class<InvalidToolCall, Schema.TaggedStruct<"InvalidToolCall", {
13
+ readonly tool: Schema.NullOr<Schema.Trimmed>;
14
+ readonly reason: Schema.Literals<readonly ["invalid_envelope", "unknown_tool", "invalid_arguments"]>;
15
+ readonly path: Schema.NullOr<Schema.Trimmed>;
16
+ }>, import("effect/Cause").YieldableError>;
20
17
  /** A model-authored tool call failed strict parsing. */
21
18
  export declare class InvalidToolCall extends InvalidToolCall_base {
22
19
  }
23
20
  /** Safe reason that an application-owned tool projection was rejected. */
24
- export declare const InvalidToolProjectionReasonSchema: Schema.Literal<["invalid_model_result", "invalid_view_data"]>;
25
- declare const InvalidToolProjection_base: Schema.TaggedErrorClass<InvalidToolProjection, "InvalidToolProjection", {
26
- readonly _tag: Schema.tag<"InvalidToolProjection">;
27
- } & {
28
- tool: Schema.filter<Schema.filter<typeof Schema.NonEmptyTrimmedString>>;
29
- target: typeof Schema.String;
30
- reason: Schema.Literal<["invalid_model_result", "invalid_view_data"]>;
31
- }>;
21
+ export declare const InvalidToolProjectionReasonSchema: Schema.Literals<readonly ["invalid_model_result", "invalid_view_data"]>;
22
+ declare const InvalidToolProjection_base: Schema.Class<InvalidToolProjection, Schema.TaggedStruct<"InvalidToolProjection", {
23
+ readonly tool: Schema.Trimmed;
24
+ readonly target: Schema.String;
25
+ readonly reason: Schema.Literals<readonly ["invalid_model_result", "invalid_view_data"]>;
26
+ }>, import("effect/Cause").YieldableError>;
32
27
  /** An application-owned model or view projection violated its schema. */
33
28
  export declare class InvalidToolProjection extends InvalidToolProjection_base {
34
29
  }
@@ -36,8 +31,10 @@ export declare class InvalidToolProjection extends InvalidToolProjection_base {
36
31
  export interface ModelToolDefinition<Name extends string = string> {
37
32
  readonly name: Name;
38
33
  readonly description: string;
39
- readonly inputSchema: JSONSchema.JsonSchema7Root;
34
+ readonly inputSchema: JsonSchema.JsonSchema;
40
35
  }
36
+ /** Schema accepted at tool boundaries without runtime services. */
37
+ export type ToolSchema = Schema.Codec<unknown, unknown, never, never>;
41
38
  /** Whether an executable model capability is repeatable or side-effecting. */
42
39
  export type ToolOperation = "query" | "command";
43
40
  /** Opaque stable identity supplied when a command executes. */
@@ -50,7 +47,7 @@ export interface ToolDefinitionContract extends StructuredDefinition<"tool"> {
50
47
  readonly operation: ToolOperation;
51
48
  readonly name: string;
52
49
  readonly description: string;
53
- readonly inputSchema: Schema.Schema.AnyNoContext;
50
+ readonly inputSchema: ToolSchema;
54
51
  readonly model: ModelToolDefinition;
55
52
  }
56
53
  /** Minimum runtime shape retained for a repeatable read-only query. */
@@ -60,10 +57,10 @@ export interface QueryToolDefinitionContract extends ToolDefinitionContract {
60
57
  /** Minimum runtime shape retained for a side-effecting command. */
61
58
  export interface CommandDefinitionContract extends ToolDefinitionContract {
62
59
  readonly operation: "command";
63
- readonly parseCall: (input: JsonValue) => Effect.Effect<ToolCall<string, Schema.Schema.AnyNoContext>, InvalidToolCall>;
60
+ readonly parseCall: (input: JsonValue) => Effect.Effect<ToolCall<string, ToolSchema>, InvalidToolCall>;
64
61
  }
65
62
  /** One model-authored, schema-parsed tool call. */
66
- export type ToolCall<Name extends string, InputSchema extends Schema.Schema.AnyNoContext> = {
63
+ export type ToolCall<Name extends string, InputSchema extends ToolSchema> = {
67
64
  readonly name: Name;
68
65
  readonly arguments: Schema.Schema.Type<InputSchema>;
69
66
  };
@@ -75,23 +72,23 @@ export interface ToolPresenter<ServerResult, View extends ViewDefinitionContract
75
72
  type PresenterView<Presenter> = Presenter extends ToolPresenter<infer _ServerResult, infer View> ? View : never;
76
73
  /** View-part union produced by one configured tool. */
77
74
  export type ToolViewPart<Presenters extends ReadonlyArray<ToolPresenter<never, ViewDefinitionContract>>> = ViewPart<PresenterView<Presenters[number]>>;
78
- type ToolModelResult<ModelSchema extends Schema.Schema.AnyNoContext | undefined> = ModelSchema extends Schema.Schema.AnyNoContext ? Schema.Schema.Type<ModelSchema> : undefined;
75
+ type ToolModelResult<ModelSchema extends ToolSchema | undefined> = ModelSchema extends ToolSchema ? Schema.Schema.Type<ModelSchema> : undefined;
79
76
  /** Complete trusted result of one parsed and executed tool call. */
80
- export interface ToolExecution<ServerResult, ModelSchema extends Schema.Schema.AnyNoContext | undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>>> {
77
+ export interface ToolExecution<ServerResult, ModelSchema extends ToolSchema | undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>>> {
81
78
  readonly serverResult: ServerResult;
82
79
  readonly modelResult: ToolModelResult<ModelSchema>;
83
80
  readonly views: ReadonlyArray<ToolViewPart<Presenters>>;
84
81
  readonly [toolExecutionModelContext]: string | undefined;
85
82
  }
86
- interface ToolModelProjection<ServerResult, ModelSchema extends Schema.Schema.AnyNoContext> {
83
+ interface ToolModelProjection<ServerResult, ModelSchema extends ToolSchema> {
87
84
  readonly schema: ModelSchema;
88
85
  readonly project: (result: ServerResult) => Schema.Schema.Type<ModelSchema>;
89
86
  }
90
- interface ToolRuntime<Name extends string, InputSchema extends Schema.Schema.AnyNoContext, ServerResult, Error, Requirements, ModelSchema extends Schema.Schema.AnyNoContext | undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>>, Operation extends ToolOperation> {
87
+ interface ToolRuntime<Name extends string, InputSchema extends ToolSchema, ServerResult, Error, Requirements, ModelSchema extends ToolSchema | undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>>, Operation extends ToolOperation> {
91
88
  readonly executeServer: (input: Schema.Schema.Type<InputSchema>, context: Operation extends "command" ? CommandExecutionContext : undefined) => Effect.Effect<ServerResult, Error, Requirements>;
92
- readonly modelProjection: ModelSchema extends Schema.Schema.AnyNoContext ? ToolModelProjection<ServerResult, ModelSchema> : undefined;
89
+ readonly modelProjection: ModelSchema extends ToolSchema ? ToolModelProjection<ServerResult, ModelSchema> : undefined;
93
90
  readonly presenters: Presenters;
94
- readonly callSchema: Schema.Schema.AnyNoContext;
91
+ readonly callSchema: ToolSchema;
95
92
  readonly name: Name;
96
93
  readonly description: string;
97
94
  readonly inputSchema: InputSchema;
@@ -105,7 +102,7 @@ interface RuntimeToolExecutionContext {
105
102
  /** @internal Read the bounded model-visible context retained by one execution. */
106
103
  export declare const readToolExecutionModelContext: (execution: RuntimeToolExecutionContext) => string | undefined;
107
104
  /** One schema-defined, executable, and pipeable query tool. */
108
- export interface StructuredTool<Name extends string, InputSchema extends Schema.Schema.AnyNoContext, ServerResult, Error, Requirements, ModelSchema extends Schema.Schema.AnyNoContext | undefined = undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>> = readonly [], Operation extends ToolOperation = "query"> extends Pipeable.Pipeable, ToolDefinitionContract {
105
+ export interface StructuredTool<Name extends string, InputSchema extends ToolSchema, ServerResult, Error, Requirements, ModelSchema extends ToolSchema | undefined = undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>> = readonly [], Operation extends ToolOperation = "query"> extends Pipeable.Pipeable, ToolDefinitionContract {
109
106
  readonly name: Name;
110
107
  readonly operation: Operation;
111
108
  readonly inputSchema: InputSchema;
@@ -120,30 +117,30 @@ export interface StructuredTool<Name extends string, InputSchema extends Schema.
120
117
  readonly [toolRuntime]: ToolRuntime<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, Presenters, Operation>;
121
118
  }
122
119
  /** One side-effecting capability accepted only by a terminal command stage. */
123
- export type StructuredCommand<Name extends string, InputSchema extends Schema.Schema.AnyNoContext, ServerResult, Error, Requirements, ModelSchema extends Schema.Schema.AnyNoContext | undefined = undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>> = readonly []> = StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, Presenters, "command">;
120
+ export type StructuredCommand<Name extends string, InputSchema extends ToolSchema, ServerResult, Error, Requirements, ModelSchema extends ToolSchema | undefined = undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>> = readonly []> = StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, Presenters, "command">;
124
121
  /** Definition input for one read-only structured chat tool. */
125
- export interface DefineToolInput<Name extends string, InputSchema extends Schema.Schema.AnyNoContext, ServerResult, Error, Requirements> {
122
+ export interface DefineToolInput<Name extends string, InputSchema extends ToolSchema, ServerResult, Error, Requirements> {
126
123
  readonly name: Name;
127
124
  readonly description: string;
128
125
  readonly input: InputSchema;
129
126
  readonly execute: (input: Schema.Schema.Type<InputSchema>) => Effect.Effect<ServerResult, Error, Requirements>;
130
127
  }
131
128
  /** Definition input for one idempotently executed structured command. */
132
- export interface DefineCommandInput<Name extends string, InputSchema extends Schema.Schema.AnyNoContext, ServerResult, Error, Requirements> {
129
+ export interface DefineCommandInput<Name extends string, InputSchema extends ToolSchema, ServerResult, Error, Requirements> {
133
130
  readonly name: Name;
134
131
  readonly description: string;
135
132
  readonly input: InputSchema;
136
133
  readonly execute: (input: Schema.Schema.Type<InputSchema>, context: CommandExecutionContext) => Effect.Effect<ServerResult, Error, Requirements>;
137
134
  }
138
135
  /** Define one read-only, schema-validated structured chat tool. */
139
- export declare const defineTool: <const Name extends string, InputSchema extends Schema.Schema.AnyNoContext, ServerResult, Error, Requirements>(definition: DefineToolInput<Name, InputSchema, ServerResult, Error, Requirements>) => StructuredTool<Name, InputSchema, ServerResult, Error, Requirements>;
136
+ export declare const defineTool: <const Name extends string, InputSchema extends ToolSchema, ServerResult, Error, Requirements>(definition: DefineToolInput<Name, InputSchema, ServerResult, Error, Requirements>) => StructuredTool<Name, InputSchema, ServerResult, Error, Requirements>;
140
137
  /** Define one side-effecting command requiring a stable idempotency key. */
141
- export declare const defineCommand: <const Name extends string, InputSchema extends Schema.Schema.AnyNoContext, ServerResult, Error, Requirements>(definition: DefineCommandInput<Name, InputSchema, ServerResult, Error, Requirements>) => StructuredCommand<Name, InputSchema, ServerResult, Error, Requirements>;
138
+ export declare const defineCommand: <const Name extends string, InputSchema extends ToolSchema, ServerResult, Error, Requirements>(definition: DefineCommandInput<Name, InputSchema, ServerResult, Error, Requirements>) => StructuredCommand<Name, InputSchema, ServerResult, Error, Requirements>;
142
139
  /** Combinators that add optional capabilities to a structured tool. */
143
140
  export declare const Tool: {
144
- readonly modelResult: <ServerResult, ModelSchema extends Schema.Schema.AnyNoContext>(schema: ModelSchema, project: (result: ServerResult) => Schema.Schema.Type<ModelSchema>) => <Name extends string, InputSchema extends Schema.Schema.AnyNoContext, Error, Requirements, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>>, Operation extends ToolOperation>(tool: StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, undefined, Presenters, Operation>) => StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, Presenters, Operation>;
145
- readonly present: <ServerResult, View extends ViewDefinitionContract>(view: View, project: (result: ServerResult) => ViewInput<View> | undefined) => <Name extends string, InputSchema extends Schema.Schema.AnyNoContext, Error, Requirements, ModelSchema extends Schema.Schema.AnyNoContext | undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>>, Operation extends ToolOperation>(tool: StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, Presenters, Operation>) => StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, readonly [...Presenters, ToolPresenter<ServerResult, View>], Operation>;
141
+ readonly modelResult: <ServerResult, ModelSchema extends ToolSchema>(schema: ModelSchema, project: (result: ServerResult) => Schema.Schema.Type<ModelSchema>) => <Name extends string, InputSchema extends ToolSchema, Error, Requirements, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>>, Operation extends ToolOperation>(tool: StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, undefined, Presenters, Operation>) => StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, Presenters, Operation>;
142
+ readonly present: <ServerResult, View extends ViewDefinitionContract>(view: View, project: (result: ServerResult) => ViewInput<View> | undefined) => <Name extends string, InputSchema extends ToolSchema, Error, Requirements, ModelSchema extends ToolSchema | undefined, Presenters extends ReadonlyArray<ToolPresenter<ServerResult, ViewDefinitionContract>>, Operation extends ToolOperation>(tool: StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, Presenters, Operation>) => StructuredTool<Name, InputSchema, ServerResult, Error, Requirements, ModelSchema, readonly [...Presenters, ToolPresenter<ServerResult, View>], Operation>;
146
143
  };
147
144
  /** Parse failure retained only for documentation of owned schema boundaries. */
148
- export type ToolBoundaryParseError = ParseResult.ParseError;
145
+ export type ToolBoundaryParseError = Schema.SchemaError;
149
146
  export {};
package/dist/core/tool.js CHANGED
@@ -1,21 +1,35 @@
1
- import { Effect, JSONSchema, Pipeable, Schema, unsafeCoerce, } from "effect";
2
- import * as ParseResult from "effect/ParseResult";
1
+ import { Effect, Function as Fn, JsonSchema, Pipeable, Result, Schema, SchemaIssue, } from "effect";
3
2
  import { structuredDefinition, } from "./definition.js";
4
3
  /** Stable machine-facing name for one structured chat tool. */
5
- export const ToolNameSchema = Schema.NonEmptyTrimmedString.pipe(Schema.maxLength(100), Schema.pattern(/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/));
4
+ export const ToolNameSchema = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.isMaxLength(100), Schema.isPattern(/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/));
6
5
  /** Bounded model-facing description for one structured chat tool. */
7
- export const ToolDescriptionSchema = Schema.NonEmptyTrimmedString.pipe(Schema.maxLength(2_000));
6
+ export const ToolDescriptionSchema = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.isMaxLength(2_000));
8
7
  /** Safe reason that a model-authored tool call was rejected. */
9
- export const InvalidToolCallReasonSchema = Schema.Literal("invalid_envelope", "unknown_tool", "invalid_arguments");
8
+ export const InvalidToolCallReasonSchema = Schema.Literals([
9
+ "invalid_envelope",
10
+ "unknown_tool",
11
+ "invalid_arguments",
12
+ ]);
10
13
  /** A model-authored tool call failed strict parsing. */
11
14
  export class InvalidToolCall extends Schema.TaggedError()("InvalidToolCall", {
12
15
  tool: Schema.NullOr(ToolNameSchema),
13
16
  reason: InvalidToolCallReasonSchema,
14
- path: Schema.NullOr(Schema.NonEmptyTrimmedString.pipe(Schema.maxLength(500))),
17
+ path: Schema.NullOr(Schema.Trimmed.check(Schema.isNonEmpty(), Schema.isMaxLength(500))),
15
18
  }) {
16
19
  }
17
20
  /** Safe reason that an application-owned tool projection was rejected. */
18
- export const InvalidToolProjectionReasonSchema = Schema.Literal("invalid_model_result", "invalid_view_data");
21
+ export const InvalidToolProjectionReasonSchema = Schema.Literals([
22
+ "invalid_model_result",
23
+ "invalid_view_data",
24
+ ]);
25
+ const StandardSchemaPathSegment = Schema.Struct({
26
+ key: Schema.Union([
27
+ Schema.String,
28
+ Schema.Number,
29
+ Schema.Symbol,
30
+ ]),
31
+ });
32
+ const decodeStandardSchemaPathSegment = Schema.decodeUnknownResult(StandardSchemaPathSegment);
19
33
  /** An application-owned model or view projection violated its schema. */
20
34
  export class InvalidToolProjection extends Schema.TaggedError()("InvalidToolProjection", {
21
35
  tool: ToolNameSchema,
@@ -25,21 +39,23 @@ export class InvalidToolProjection extends Schema.TaggedError()("InvalidToolProj
25
39
  }
26
40
  const toolRuntime = Symbol("@popcomputer/structured-chat/ToolRuntime");
27
41
  const toolExecutionModelContext = Symbol("@popcomputer/structured-chat/ToolExecutionModelContext");
28
- const ToolExecutionModelContextSchema = Schema.NonEmptyTrimmedString.pipe(Schema.maxLength(40_000));
42
+ const ToolExecutionModelContextSchema = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.isMaxLength(40_000));
29
43
  /** @internal Read the bounded model-visible context retained by one execution. */
30
44
  export const readToolExecutionModelContext = (execution) => {
31
- // SAFETY: Every execution returned by a StructuredTool is constructed by
32
- // makeTool below with this package-private symbol property.
33
- const runtime = execution;
34
- return runtime[toolExecutionModelContext];
45
+ return execution[toolExecutionModelContext];
35
46
  };
36
- const parseToolCall = (name, callSchema, input) => Schema.decodeUnknown(callSchema)(input, {
47
+ const parseToolCall = (name, callSchema, input) => Schema.decodeUnknownEffect(callSchema)(input, {
37
48
  onExcessProperty: "error",
38
49
  }).pipe(Effect.mapError((error) => {
39
- const issue = ParseResult.ArrayFormatter.formatErrorSync(error)[0];
40
- const issuePath = issue === undefined || issue.path.length === 0
50
+ const issue = SchemaIssue.makeFormatterStandardSchemaV1()(error.issue)
51
+ .issues[0];
52
+ const path = issue?.path ?? [];
53
+ const issuePath = path.length === 0
41
54
  ? "#"
42
- : `#/${issue.path.map(String).join("/")}`;
55
+ : `#/${path.map((segment) => Result.match(decodeStandardSchemaPathSegment(segment), {
56
+ onFailure: () => String(segment),
57
+ onSuccess: ({ key }) => String(key),
58
+ })).join("/")}`;
43
59
  return new InvalidToolCall({
44
60
  tool: name,
45
61
  reason: "invalid_arguments",
@@ -50,7 +66,7 @@ const projectModelResult = (tool, projection, result) => {
50
66
  if (projection === undefined) {
51
67
  // SAFETY: The conditional result type is exactly undefined when no model
52
68
  // projection schema is configured.
53
- return Effect.succeed(undefined);
69
+ return Effect.succeed(Fn.cast(undefined));
54
70
  }
55
71
  const invalidProjection = () => new InvalidToolProjection({
56
72
  tool,
@@ -60,21 +76,21 @@ const projectModelResult = (tool, projection, result) => {
60
76
  return Effect.try({
61
77
  try: () => projection.project(result),
62
78
  catch: invalidProjection,
63
- }).pipe(Effect.flatMap((projected) => Schema.validate(projection.schema)(projected, {
79
+ }).pipe(Effect.flatMap((projected) => Schema.decodeEffect(Schema.toType(projection.schema))(projected, {
64
80
  onExcessProperty: "error",
65
81
  })), Effect.mapError(invalidProjection),
66
- // SAFETY: Schema.validate returned the configured model schema's exact
82
+ // SAFETY: decoding the Type side returned the configured schema's exact
67
83
  // Type side, which is ToolModelResult<ModelSchema> in this branch.
68
- Effect.map((value) => value));
84
+ Effect.map((value) => Fn.cast(value)));
69
85
  };
70
86
  const encodeToolExecutionModelContext = (tool, projection, modelResult) => {
71
87
  if (projection === undefined) {
72
88
  return Effect.succeed(undefined);
73
89
  }
74
- return Schema.encodeUnknown(projection.schema)(modelResult).pipe(Effect.flatMap((encodedResult) => Schema.encodeUnknown(Schema.parseJson())({
90
+ return Schema.encodeUnknownEffect(projection.schema)(modelResult).pipe(Effect.flatMap((encodedResult) => Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))({
75
91
  tool,
76
92
  result: encodedResult,
77
- })), Effect.flatMap((context) => Schema.decodeUnknown(ToolExecutionModelContextSchema)(context)), Effect.mapError(() => new InvalidToolProjection({
93
+ })), Effect.flatMap((context) => Schema.decodeUnknownEffect(ToolExecutionModelContextSchema)(context)), Effect.mapError(() => new InvalidToolProjection({
78
94
  tool,
79
95
  target: "model_context",
80
96
  reason: "invalid_model_result",
@@ -95,17 +111,28 @@ const projectViews = (tool, presenters, result) => Effect.forEach(presenters, (p
95
111
  }).pipe(Effect.map((parts) => parts.flatMap((part) => part === undefined ? [] : [part])), Effect.map((parts) => {
96
112
  // SAFETY: Every retained part was parsed by the corresponding presenter
97
113
  // view, and the output union is derived from that same presenter tuple.
98
- return unsafeCoerce(parts);
114
+ return Fn.cast(parts);
99
115
  }));
116
+ const makeModelInputSchema = (schema) => {
117
+ const document = JsonSchema.toDocumentDraft07(Schema.toJsonSchemaDocument(schema));
118
+ const definitions = Object.keys(document.definitions).length === 0
119
+ ? {}
120
+ : { definitions: document.definitions };
121
+ return {
122
+ $schema: JsonSchema.META_SCHEMA_URI_DRAFT_07,
123
+ ...document.schema,
124
+ ...definitions,
125
+ };
126
+ };
100
127
  const makeTool = (runtime) => {
101
128
  // SAFETY: ToolRuntime.callSchema is constructed from this tool's exact
102
129
  // literal name and InputSchema before makeTool is called.
103
- const callSchema = runtime.callSchema;
130
+ const callSchema = Fn.cast(runtime.callSchema);
104
131
  const parseCall = (input) => parseToolCall(runtime.name, callSchema, input);
105
132
  const executeRuntime = (input, context) => runtime.executeServer(input,
106
133
  // SAFETY: command constructors expose a required context while query
107
134
  // constructors expose no context; runtime.operation owns that invariant.
108
- unsafeCoerce(context)).pipe(Effect.flatMap((serverResult) => Effect.all({
135
+ Fn.cast(context)).pipe(Effect.flatMap((serverResult) => Effect.all({
109
136
  modelResult: projectModelResult(runtime.name, runtime.modelProjection, serverResult),
110
137
  views: projectViews(runtime.name, runtime.presenters, serverResult),
111
138
  }).pipe(Effect.flatMap(({ modelResult, views }) => encodeToolExecutionModelContext(runtime.name, runtime.modelProjection, modelResult).pipe(Effect.map((modelContext) => ({
@@ -118,7 +145,7 @@ const makeTool = (runtime) => {
118
145
  }));
119
146
  // SAFETY: command constructors expose a required context while query
120
147
  // constructors expose no context; both feed this operation-tagged runtime.
121
- const execute = unsafeCoerce(executeRuntime);
148
+ const execute = Fn.cast(executeRuntime);
122
149
  const executeCallRuntime = (input, context) => parseCall(input).pipe(Effect.flatMap((call) => executeRuntime(call.arguments, context)));
123
150
  return structuredDefinition("tool")({
124
151
  _tag: "StructuredTool",
@@ -130,11 +157,11 @@ const makeTool = (runtime) => {
130
157
  model: {
131
158
  name: runtime.name,
132
159
  description: runtime.description,
133
- inputSchema: JSONSchema.make(runtime.inputSchema),
160
+ inputSchema: makeModelInputSchema(runtime.inputSchema),
134
161
  },
135
162
  parseCall,
136
163
  execute,
137
- executeCall: unsafeCoerce(executeCallRuntime),
164
+ executeCall: Fn.cast(executeCallRuntime),
138
165
  [toolRuntime]: runtime,
139
166
  pipe() {
140
167
  return Pipeable.pipeArguments(this, arguments);
@@ -153,7 +180,7 @@ export const defineTool = (definition) => {
153
180
  });
154
181
  // SAFETY: the literal name and input schema are exactly the two ToolCall
155
182
  // fields, and the constituent schemas require no runtime context.
156
- const callSchema = unsafeCoerce(rawCallSchema);
183
+ const callSchema = Fn.cast(rawCallSchema);
157
184
  return makeTool({
158
185
  name,
159
186
  description,
@@ -174,7 +201,7 @@ export const defineCommand = (definition) => {
174
201
  arguments: definition.input,
175
202
  });
176
203
  // SAFETY: the literal name and input schema exactly form ToolCall.
177
- const callSchema = unsafeCoerce(rawCallSchema);
204
+ const callSchema = Fn.cast(rawCallSchema);
178
205
  return makeTool({
179
206
  name: definition.name,
180
207
  description: definition.description,
@@ -195,7 +222,7 @@ const modelResult = (schema, project) => (tool) => {
195
222
  };
196
223
  // SAFETY: this combinator changes only the model-projection slot from
197
224
  // absent to the exact supplied schema and projector.
198
- return makeTool(unsafeCoerce(nextRuntime));
225
+ return makeTool(Fn.cast(nextRuntime));
199
226
  };
200
227
  /** Add one optional display-safe view projection to a tool. */
201
228
  const present = (view, project) => (tool) => {
@@ -1,38 +1,47 @@
1
- import { Effect, Either, Schema } from "effect";
2
- import type * as ParseResult from "effect/ParseResult";
1
+ import { Effect, Result, Schema } from "effect";
3
2
  import type { JsonValue } from "./json-value.js";
4
3
  /** Stable machine-facing name for one structured chat view. */
5
- export declare const ViewNameSchema: Schema.filter<Schema.filter<typeof Schema.NonEmptyTrimmedString>>;
4
+ export declare const ViewNameSchema: Schema.Trimmed;
6
5
  /** Positive protocol version for one structured chat view. */
7
- export declare const ViewVersionSchema: Schema.filter<Schema.filter<typeof Schema.Number>>;
6
+ export declare const ViewVersionSchema: Schema.Number;
7
+ /** Schema accepted at view boundaries without runtime services. */
8
+ export type ViewSchema = Schema.Codec<unknown, unknown, never, never>;
9
+ /** Schema for one decoded view part correlated with its view data. */
10
+ export type ViewPartSchema<Name extends string = string, DataSchema extends ViewSchema = ViewSchema> = Schema.Codec<{
11
+ readonly type: "data";
12
+ readonly name: Name;
13
+ readonly data: Schema.Schema.Type<DataSchema>;
14
+ }, unknown, never, never>;
8
15
  /** Minimum runtime shape retained for every structured chat view. */
9
- export interface ViewDefinitionContract<Name extends string = string, Version extends number = number, InputSchema extends Schema.Schema.AnyNoContext = Schema.Schema.AnyNoContext, DataSchema extends Schema.Schema.AnyNoContext = Schema.Schema.AnyNoContext, PartSchema extends Schema.Schema.AnyNoContext = Schema.Schema.AnyNoContext> {
16
+ export interface ViewDefinitionContract<Name extends string = string, Version extends number = number, InputSchema extends ViewSchema = ViewSchema, DataSchema extends ViewSchema = ViewSchema, PartSchema extends ViewPartSchema<Name, DataSchema> = ViewPartSchema<Name, DataSchema>> {
10
17
  readonly name: Name;
11
18
  readonly version: Version;
12
19
  readonly inputSchema: InputSchema;
13
20
  readonly dataSchema: DataSchema;
14
21
  readonly partSchema: PartSchema;
15
22
  /** Parse unknown application data into one display-safe data part. */
16
- readonly parseData: (input: JsonValue) => Effect.Effect<Schema.Schema.Type<PartSchema>, ParseResult.ParseError>;
23
+ parseData(input: ViewInput<this>): Effect.Effect<ViewPart<this>, Schema.SchemaError>;
17
24
  /** Parse an unknown serialized part without requiring an Effect runtime. */
18
- readonly decodeEither: (input: JsonValue) => Either.Either<Schema.Schema.Type<PartSchema>, ParseResult.ParseError>;
25
+ decodeResult(input: JsonValue): Result.Result<ViewPart<this>, Schema.SchemaError>;
19
26
  }
20
27
  /** Parsed data accepted when constructing one view part. */
21
28
  export type ViewInput<View extends ViewDefinitionContract> = Schema.Schema.Type<View["inputSchema"]>;
22
29
  /** Versioned display data carried by one view part. */
23
30
  export type ViewData<View extends ViewDefinitionContract> = Schema.Schema.Type<View["dataSchema"]>;
24
31
  /** Complete structured message part produced by one view. */
25
- export type ViewPart<View extends ViewDefinitionContract> = Schema.Schema.Type<View["partSchema"]>;
32
+ export type ViewPart<View extends ViewDefinitionContract> = Schema.Schema.Type<View["partSchema"]> & {
33
+ readonly data: ViewData<View>;
34
+ };
26
35
  /** One schema-defined, versioned structured chat view. */
27
- export interface ViewDefinition<Name extends string, Version extends number, InputSchema extends Schema.Schema.AnyNoContext, DataSchema extends Schema.Schema.AnyNoContext, PartSchema extends Schema.Schema.AnyNoContext> extends ViewDefinitionContract<Name, Version, InputSchema, DataSchema, PartSchema> {
36
+ export interface ViewDefinition<Name extends string, Version extends number, InputSchema extends ViewSchema, DataSchema extends ViewSchema, PartSchema extends ViewPartSchema<Name, DataSchema>> extends ViewDefinitionContract<Name, Version, InputSchema, DataSchema, PartSchema> {
28
37
  /** Construct and validate one display-safe data part. */
29
- readonly make: (input: Schema.Schema.Type<InputSchema>) => Schema.Schema.Type<PartSchema>;
38
+ make(input: Schema.Schema.Type<InputSchema>): Schema.Schema.Type<PartSchema>;
30
39
  /** Parse unknown input into one display-safe data part. */
31
- readonly parseData: (input: JsonValue) => Effect.Effect<Schema.Schema.Type<PartSchema>, ParseResult.ParseError>;
40
+ parseData(input: ViewInput<this>): Effect.Effect<ViewPart<this>, Schema.SchemaError>;
32
41
  /** Parse an unknown serialized part at a runtime boundary. */
33
- readonly decode: (input: JsonValue) => Effect.Effect<Schema.Schema.Type<PartSchema>, ParseResult.ParseError>;
42
+ decode(input: JsonValue): Effect.Effect<ViewPart<this>, Schema.SchemaError>;
34
43
  /** Parse an unknown serialized part without requiring an Effect runtime. */
35
- readonly decodeEither: (input: JsonValue) => Either.Either<Schema.Schema.Type<PartSchema>, ParseResult.ParseError>;
44
+ decodeResult(input: JsonValue): Result.Result<ViewPart<this>, Schema.SchemaError>;
36
45
  }
37
46
  /** Definition input for one versioned structured chat view. */
38
47
  export interface DefineViewInput<Name extends string, Version extends number, Fields extends Schema.Struct.Fields> {
@@ -41,7 +50,7 @@ export interface DefineViewInput<Name extends string, Version extends number, Fi
41
50
  readonly schema: Schema.Struct<Fields>;
42
51
  }
43
52
  type NoContextFields<Fields extends Schema.Struct.Fields> = [
44
- Schema.Struct.Context<Fields>
53
+ Schema.Struct.DecodingServices<Fields> | Schema.Struct.EncodingServices<Fields>
45
54
  ] extends [never] ? unknown : never;
46
55
  /**
47
56
  * Define one typed server-to-browser view contract.
@@ -54,42 +63,58 @@ export declare const defineView: <const Name extends string, const Version exten
54
63
  version: Version;
55
64
  inputSchema: Schema.Struct<Fields>;
56
65
  dataSchema: Schema.Struct<{
57
- readonly schemaVersion: Schema.Literal<[Version]>;
66
+ readonly schemaVersion: Schema.Literal<Version>;
58
67
  } & Fields>;
59
68
  partSchema: Schema.Struct<{
60
- readonly type: Schema.Literal<["data"]>;
61
- readonly name: Schema.Literal<[Name]>;
69
+ readonly type: Schema.Literal<"data">;
70
+ readonly name: Schema.Literal<Name>;
62
71
  readonly data: Schema.Struct<{
63
- readonly schemaVersion: Schema.Literal<[Version]>;
72
+ readonly schemaVersion: Schema.Literal<Version>;
64
73
  } & Fields>;
65
74
  }>;
66
- make: (input: Schema.Struct.Type<Fields> extends infer T ? { [K in keyof T]: T[K]; } : never) => {
67
- readonly name: Name;
75
+ make: (input: Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>) => {
68
76
  readonly type: "data";
69
- readonly data: Schema.Struct.Type<{
70
- readonly schemaVersion: Schema.Literal<[Version]>;
71
- } & Fields> extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1]; } : never;
72
- };
73
- parseData: (input: JsonValue) => Effect.Effect<{
74
77
  readonly name: Name;
78
+ readonly data: Schema.Struct.View<{
79
+ readonly schemaVersion: Schema.Literal<Version>;
80
+ } & Fields, "Type", Schema.Struct.TypeOptionalKeys<{
81
+ readonly schemaVersion: Schema.Literal<Version>;
82
+ } & Fields>, Schema.Struct.TypeMutableKeys<{
83
+ readonly schemaVersion: Schema.Literal<Version>;
84
+ } & Fields>>;
85
+ };
86
+ parseData: (input: Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>) => Effect.Effect<{
75
87
  readonly type: "data";
76
- readonly data: Schema.Struct.Type<{
77
- readonly schemaVersion: Schema.Literal<[Version]>;
78
- } & Fields> extends infer T ? { [K in keyof T]: T[K]; } : never;
79
- }, ParseResult.ParseError>;
80
- decode: (input: JsonValue) => Effect.Effect<{
81
88
  readonly name: Name;
89
+ readonly data: Schema.Struct.View<{
90
+ readonly schemaVersion: Schema.Literal<Version>;
91
+ } & Fields, "Type", Schema.Struct.TypeOptionalKeys<{
92
+ readonly schemaVersion: Schema.Literal<Version>;
93
+ } & Fields>, Schema.Struct.TypeMutableKeys<{
94
+ readonly schemaVersion: Schema.Literal<Version>;
95
+ } & Fields>>;
96
+ }, Schema.SchemaError>;
97
+ decode: (input: JsonValue) => Effect.Effect<{
82
98
  readonly type: "data";
83
- readonly data: Schema.Struct.Type<{
84
- readonly schemaVersion: Schema.Literal<[Version]>;
85
- } & Fields> extends infer T ? { [K in keyof T]: T[K]; } : never;
86
- }, ParseResult.ParseError, never>;
87
- decodeEither: (input: JsonValue) => Either.Either<{
88
99
  readonly name: Name;
100
+ readonly data: Schema.Struct.View<{
101
+ readonly schemaVersion: Schema.Literal<Version>;
102
+ } & Fields, "Type", Schema.Struct.TypeOptionalKeys<{
103
+ readonly schemaVersion: Schema.Literal<Version>;
104
+ } & Fields>, Schema.Struct.TypeMutableKeys<{
105
+ readonly schemaVersion: Schema.Literal<Version>;
106
+ } & Fields>>;
107
+ }, Schema.SchemaError, never>;
108
+ decodeResult: (input: JsonValue) => Result.Result<{
89
109
  readonly type: "data";
90
- readonly data: Schema.Struct.Type<{
91
- readonly schemaVersion: Schema.Literal<[Version]>;
92
- } & Fields> extends infer T ? { [K in keyof T]: T[K]; } : never;
93
- }, ParseResult.ParseError>;
110
+ readonly name: Name;
111
+ readonly data: Schema.Struct.View<{
112
+ readonly schemaVersion: Schema.Literal<Version>;
113
+ } & Fields, "Type", Schema.Struct.TypeOptionalKeys<{
114
+ readonly schemaVersion: Schema.Literal<Version>;
115
+ } & Fields>, Schema.Struct.TypeMutableKeys<{
116
+ readonly schemaVersion: Schema.Literal<Version>;
117
+ } & Fields>>;
118
+ }, Schema.SchemaError>;
94
119
  };
95
120
  export {};