@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.
- package/LICENSE +0 -1
- package/README.md +175 -108
- package/dist/adapters/openai-compatible-model.d.ts +4 -4
- package/dist/adapters/openai-compatible-model.js +33 -31
- package/dist/core/answer.d.ts +13 -13
- package/dist/core/answer.js +21 -12
- package/dist/core/chat.d.ts +12 -15
- package/dist/core/chat.js +36 -27
- package/dist/core/collect-stage.d.ts +28 -15
- package/dist/core/collect-stage.js +58 -37
- package/dist/core/command.d.ts +1 -1
- package/dist/core/command.js +1 -1
- package/dist/core/debug-protocol.d.ts +126 -0
- package/dist/core/debug-protocol.js +19 -0
- package/dist/core/debug.d.ts +103 -0
- package/dist/core/debug.js +276 -0
- package/dist/core/json-value.d.ts +1 -1
- package/dist/core/json-value.js +8 -1
- package/dist/core/model-guard.d.ts +2 -3
- package/dist/core/model-guard.js +4 -4
- package/dist/core/model.d.ts +15 -19
- package/dist/core/model.js +22 -10
- package/dist/core/protocol.d.ts +84 -79
- package/dist/core/protocol.js +18 -12
- package/dist/core/question.js +17 -15
- package/dist/core/repair.js +1 -1
- package/dist/core/session.d.ts +22 -28
- package/dist/core/session.js +16 -7
- package/dist/core/stage-name.d.ts +1 -1
- package/dist/core/stage-name.js +1 -1
- package/dist/core/stage.d.ts +4 -4
- package/dist/core/stage.js +11 -8
- package/dist/core/tool-set.js +6 -6
- package/dist/core/tool.d.ts +36 -39
- package/dist/core/tool.js +58 -31
- package/dist/core/view.d.ts +64 -39
- package/dist/core/view.js +12 -15
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/integrations/assistant-ui-debug.d.ts +25 -0
- package/dist/integrations/assistant-ui-debug.js +1162 -0
- package/dist/integrations/assistant-ui.d.ts +10 -3
- package/dist/integrations/assistant-ui.js +48 -18
- package/dist/testing/in-memory-session-store.js +1 -1
- package/dist/testing/scenario.js +6 -6
- package/examples/answer-modes.ts +60 -49
- package/examples/prompt-injection-policy.ts +20 -20
- package/examples/resource-search.ts +104 -0
- package/package.json +15 -3
- package/examples/agency-search.ts +0 -101
package/dist/core/view.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Effect,
|
|
1
|
+
import { Effect, Function as Fn, Result, Schema } from "effect";
|
|
2
2
|
/** Stable machine-facing name for one structured chat view. */
|
|
3
|
-
export const ViewNameSchema = Schema.
|
|
3
|
+
export const ViewNameSchema = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.isMaxLength(100), Schema.isPattern(/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/));
|
|
4
4
|
/** Positive protocol version for one structured chat view. */
|
|
5
|
-
export const ViewVersionSchema = Schema.Number.
|
|
5
|
+
export const ViewVersionSchema = Schema.Number.check(Schema.isInt(), Schema.isBetween({ minimum: 1, maximum: 2_147_483_647 }));
|
|
6
6
|
/**
|
|
7
7
|
* Define one typed server-to-browser view contract.
|
|
8
8
|
*
|
|
@@ -15,14 +15,10 @@ export const defineView = (definition) => {
|
|
|
15
15
|
if ("schemaVersion" in definition.schema.fields) {
|
|
16
16
|
throw new Error("View schemas cannot define the reserved schemaVersion field");
|
|
17
17
|
}
|
|
18
|
-
// SAFETY: the reserved schemaVersion field cannot be supplied by Fields;
|
|
19
|
-
// the literal therefore augments the exact application schema once.
|
|
20
18
|
const dataSchema = Schema.Struct({
|
|
21
19
|
schemaVersion: Schema.Literal(definition.version),
|
|
22
20
|
...definition.schema.fields,
|
|
23
21
|
});
|
|
24
|
-
// SAFETY: these literals and dataSchema exactly describe ViewPart<Name,
|
|
25
|
-
// Version, Fields>; the assertions retain that generic correlation.
|
|
26
22
|
const partSchema = Schema.Struct({
|
|
27
23
|
type: Schema.Literal("data"),
|
|
28
24
|
name: Schema.Literal(definition.name),
|
|
@@ -30,14 +26,15 @@ export const defineView = (definition) => {
|
|
|
30
26
|
});
|
|
31
27
|
// SAFETY: NoContextFields excludes schemas with runtime requirements; this
|
|
32
28
|
// assertion preserves definition.schema's existing Type and Encoded sides.
|
|
33
|
-
const runtimeInputSchema =
|
|
29
|
+
const runtimeInputSchema = Fn.cast(definition.schema);
|
|
34
30
|
// SAFETY: partSchema was built immediately above from the exact view name,
|
|
35
31
|
// version, and application fields, with no runtime schema requirements.
|
|
36
|
-
const runtimePartSchema =
|
|
37
|
-
const decodePart = Schema.
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
32
|
+
const runtimePartSchema = Fn.cast(partSchema);
|
|
33
|
+
const decodePart = Schema.decodeUnknownEffect(runtimePartSchema);
|
|
34
|
+
const decodePartResult = Schema.decodeUnknownResult(runtimePartSchema);
|
|
35
|
+
const validateInput = Schema.decodeUnknownEffect(Schema.toType(runtimeInputSchema));
|
|
36
|
+
const validatePart = Schema.decodeUnknownEffect(Schema.toType(runtimePartSchema));
|
|
37
|
+
const parseData = (input) => validateInput(input, {
|
|
41
38
|
onExcessProperty: "error",
|
|
42
39
|
}).pipe(Effect.flatMap((data) => validatePart({
|
|
43
40
|
type: "data",
|
|
@@ -47,7 +44,7 @@ export const defineView = (definition) => {
|
|
|
47
44
|
...data,
|
|
48
45
|
},
|
|
49
46
|
}, { onExcessProperty: "error" })));
|
|
50
|
-
const make = (input) => Schema.
|
|
47
|
+
const make = (input) => Schema.decodeUnknownSync(Schema.toType(runtimePartSchema))({
|
|
51
48
|
type: "data",
|
|
52
49
|
name: definition.name,
|
|
53
50
|
data: {
|
|
@@ -64,6 +61,6 @@ export const defineView = (definition) => {
|
|
|
64
61
|
make,
|
|
65
62
|
parseData,
|
|
66
63
|
decode: (input) => decodePart(input, { onExcessProperty: "error" }),
|
|
67
|
-
|
|
64
|
+
decodeResult: (input) => decodePartResult(input, { onExcessProperty: "error" }),
|
|
68
65
|
};
|
|
69
66
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { AssistantDataPartSchema, AssistantMessagePartSchema, AssistantTextPartSchema, CollectQuestionView, InvalidChatPresentation, presentAnswerValidationRejection, presentChatNotice, presentChatReply, StructuredChatAssistantMessageSchema, StructuredChatSessionReferenceSchema, StructuredChatTurnRequestSchema, StructuredChatTurnResponseSchema, Text, type AssistantMessagePart, type PresentChatReplyOptions, type StructuredChatAssistantMessage, type StructuredChatSessionReference, type StructuredChatTurnRequest, type StructuredChatTurnResponse, } from "./core/protocol.js";
|
|
2
|
+
export { inspectChatState, InvalidChatDebugProjection, StructuredChatDebugSnapshotSchema, type InspectChatStateOptions, type StructuredChatDebugSnapshot, } from "./core/debug.js";
|
|
3
|
+
export { presentChatDebugReply, StructuredChatDebugTurnResponseSchema, type PresentChatDebugReplyOptions, type StructuredChatDebugTurnResponse, } from "./core/debug-protocol.js";
|
|
2
4
|
export { makeStructuredChatModel, ModelProvider, structuredChatModelLayer, StructuredChatModelIdSchema, StructuredChatProviderIdSchema, StructuredChatRequestTimeoutSchema, type CloudflareWorkersAIProviderConfig, type OpenAIProviderConfig, type StructuredChatModelConfig, type StructuredChatModelId, type StructuredChatProvider, type StructuredChatProviderId, type StructuredChatProviderRequest, } from "./adapters/openai-compatible-model.js";
|
|
3
5
|
export { ChatNameSchema, ChatVersionSchema, defineChat, InvalidChatTransition, InvalidChatTransitionReasonSchema, type ChatDefinition, type ChatError, type ChatRequirements, type ChatReply, type ChatReplyError, type ChatReplyInput, type ChatStageStates, type ChatStageTuple, type ChatState, type ChatTurn, type DefineChatInput, } from "./core/chat.js";
|
|
4
6
|
export { Answer, AnswerModeSchema, type AnswerDefinition, type AnswerDefinitionContract, type AnswerMode, type DefineAnswerInput, type DefineUnvalidatedAnswerInput, type DefineValidatedAnswerInput, } from "./core/answer.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { AssistantDataPartSchema, AssistantMessagePartSchema, AssistantTextPartSchema, CollectQuestionView, InvalidChatPresentation, presentAnswerValidationRejection, presentChatNotice, presentChatReply, StructuredChatAssistantMessageSchema, StructuredChatSessionReferenceSchema, StructuredChatTurnRequestSchema, StructuredChatTurnResponseSchema, Text, } from "./core/protocol.js";
|
|
2
|
+
export { inspectChatState, InvalidChatDebugProjection, StructuredChatDebugSnapshotSchema, } from "./core/debug.js";
|
|
3
|
+
export { presentChatDebugReply, StructuredChatDebugTurnResponseSchema, } from "./core/debug-protocol.js";
|
|
2
4
|
export { makeStructuredChatModel, ModelProvider, structuredChatModelLayer, StructuredChatModelIdSchema, StructuredChatProviderIdSchema, StructuredChatRequestTimeoutSchema, } from "./adapters/openai-compatible-model.js";
|
|
3
5
|
export { ChatNameSchema, ChatVersionSchema, defineChat, InvalidChatTransition, InvalidChatTransitionReasonSchema, } from "./core/chat.js";
|
|
4
6
|
export { Answer, AnswerModeSchema, } from "./core/answer.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { StructuredChatDebugSnapshot } from "../core/debug.js";
|
|
2
|
+
/** Viewport corner used by the structured-chat debug panel. */
|
|
3
|
+
export type StructuredChatDebugPanelPosition = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
4
|
+
/** Color treatment used by the structured-chat debug panel. */
|
|
5
|
+
export type StructuredChatDebugPanelTheme = "system" | "light" | "dark";
|
|
6
|
+
/** Explicit in-memory source consumed by one structured-chat debug panel. */
|
|
7
|
+
export interface StructuredChatDebugStore {
|
|
8
|
+
/** Replace the current snapshot and notify active subscribers. */
|
|
9
|
+
readonly receive: (snapshot: StructuredChatDebugSnapshot) => void;
|
|
10
|
+
/** Subscribe to snapshot replacement. */
|
|
11
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
12
|
+
/** Read the current snapshot, or null before the first reply. */
|
|
13
|
+
readonly getSnapshot: () => StructuredChatDebugSnapshot | null;
|
|
14
|
+
}
|
|
15
|
+
/** Create one isolated structured-chat debug snapshot store. */
|
|
16
|
+
export declare const createStructuredChatDebugStore: () => StructuredChatDebugStore;
|
|
17
|
+
/** Props for the fixed, collapsible structured-chat debug panel. */
|
|
18
|
+
export interface StructuredChatDebugPanelProps {
|
|
19
|
+
readonly store: StructuredChatDebugStore;
|
|
20
|
+
readonly position?: StructuredChatDebugPanelPosition;
|
|
21
|
+
readonly theme?: StructuredChatDebugPanelTheme;
|
|
22
|
+
readonly defaultOpen?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Render one fixed, accessible inspector for the latest debug snapshot. */
|
|
25
|
+
export declare const StructuredChatDebugPanel: ({ store, position, theme, defaultOpen, }: StructuredChatDebugPanelProps) => import("react").JSX.Element;
|