@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,101 +0,0 @@
1
- import {
2
- Context,
3
- Effect,
4
- Layer,
5
- Schema,
6
- } from "effect"
7
- import {
8
- defineTool,
9
- defineView,
10
- Message,
11
- Stage,
12
- Tool,
13
- } from "@popcomputer/structured-chat"
14
-
15
- interface AgencyMatch {
16
- readonly id: string
17
- readonly name: string
18
- readonly reason: string
19
- readonly internalScore: number
20
- readonly retrievedText: string
21
- }
22
-
23
- class AgencyCatalog extends Context.Tag("AgencyCatalog")<
24
- AgencyCatalog,
25
- {
26
- readonly search: (
27
- query: string,
28
- ) => Effect.Effect<ReadonlyArray<AgencyMatch>>
29
- }
30
- >() {}
31
-
32
- const AgencyCards = defineView({
33
- name: "agency_cards",
34
- version: 1,
35
- schema: Schema.Struct({
36
- agencies: Schema.Array(
37
- Schema.Struct({
38
- id: Schema.String,
39
- name: Schema.String,
40
- reason: Schema.String,
41
- }),
42
- ),
43
- }),
44
- })
45
-
46
- const AgencyEvidence = Schema.Struct({
47
- matches: Schema.Array(
48
- Schema.Struct({
49
- id: Schema.String,
50
- reason: Schema.String,
51
- }),
52
- ),
53
- })
54
-
55
- export const SearchAgencies = defineTool({
56
- name: "search_agencies",
57
- description: "Find agencies relevant to the project.",
58
- input: Schema.Struct({ query: Schema.NonEmptyTrimmedString }),
59
- execute: ({ query }) =>
60
- AgencyCatalog.pipe(
61
- Effect.flatMap((catalog) => catalog.search(query)),
62
- ),
63
- }).pipe(
64
- Tool.modelResult(AgencyEvidence, (matches) => ({
65
- matches: matches.map(({ id, reason }) => ({ id, reason })),
66
- })),
67
- Tool.present(AgencyCards, (matches) => ({
68
- agencies: matches.map(({ id, name, reason }) => ({
69
- id,
70
- name,
71
- reason,
72
- })),
73
- })),
74
- )
75
-
76
- export const Matching = Stage.tools({
77
- name: "matching",
78
- instructions: ["Route the project brief to one agency search."],
79
- tools: [SearchAgencies],
80
- })
81
-
82
- const AgencyCatalogLive = Layer.succeed(AgencyCatalog, {
83
- search: () =>
84
- Effect.succeed([
85
- {
86
- id: "agency:1",
87
- name: "Northbank",
88
- reason: "Relevant public-sector transformation work.",
89
- internalScore: 0.93,
90
- retrievedText: "Untrusted source text remains server-side.",
91
- },
92
- ]),
93
- })
94
-
95
- export const example = SearchAgencies.execute({
96
- query: "A public-sector digital service",
97
- }).pipe(Effect.provide(AgencyCatalogLive))
98
-
99
- export const stageExample = Matching.run([
100
- Message.user("We need a public-sector digital service."),
101
- ])