@intelligo-dev/chat 1.0.0-beta.13

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 (94) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +6 -0
  3. package/README.md +116 -0
  4. package/dist/artifact-writer.d.ts +45 -0
  5. package/dist/artifact-writer.d.ts.map +1 -0
  6. package/dist/artifact-writer.js +77 -0
  7. package/dist/artifact-writer.js.map +1 -0
  8. package/dist/attachments.d.ts +56 -0
  9. package/dist/attachments.d.ts.map +1 -0
  10. package/dist/attachments.js +204 -0
  11. package/dist/attachments.js.map +1 -0
  12. package/dist/body.d.ts +72 -0
  13. package/dist/body.d.ts.map +1 -0
  14. package/dist/body.js +174 -0
  15. package/dist/body.js.map +1 -0
  16. package/dist/client.d.ts +65 -0
  17. package/dist/client.d.ts.map +1 -0
  18. package/dist/client.js +61 -0
  19. package/dist/client.js.map +1 -0
  20. package/dist/config.d.ts +322 -0
  21. package/dist/config.d.ts.map +1 -0
  22. package/dist/config.js +11 -0
  23. package/dist/config.js.map +1 -0
  24. package/dist/errors.d.ts +23 -0
  25. package/dist/errors.d.ts.map +1 -0
  26. package/dist/errors.js +41 -0
  27. package/dist/errors.js.map +1 -0
  28. package/dist/feedback.d.ts +22 -0
  29. package/dist/feedback.d.ts.map +1 -0
  30. package/dist/feedback.js +46 -0
  31. package/dist/feedback.js.map +1 -0
  32. package/dist/generation.d.ts +104 -0
  33. package/dist/generation.d.ts.map +1 -0
  34. package/dist/generation.js +85 -0
  35. package/dist/generation.js.map +1 -0
  36. package/dist/handler.d.ts +30 -0
  37. package/dist/handler.d.ts.map +1 -0
  38. package/dist/handler.js +913 -0
  39. package/dist/handler.js.map +1 -0
  40. package/dist/index.d.ts +31 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +20 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/messages.d.ts +19 -0
  45. package/dist/messages.d.ts.map +1 -0
  46. package/dist/messages.js +34 -0
  47. package/dist/messages.js.map +1 -0
  48. package/dist/parts.d.ts +117 -0
  49. package/dist/parts.d.ts.map +1 -0
  50. package/dist/parts.js +13 -0
  51. package/dist/parts.js.map +1 -0
  52. package/dist/quota.d.ts +32 -0
  53. package/dist/quota.d.ts.map +1 -0
  54. package/dist/quota.js +81 -0
  55. package/dist/quota.js.map +1 -0
  56. package/dist/share.d.ts +24 -0
  57. package/dist/share.d.ts.map +1 -0
  58. package/dist/share.js +78 -0
  59. package/dist/share.js.map +1 -0
  60. package/dist/testing.d.ts +36 -0
  61. package/dist/testing.d.ts.map +1 -0
  62. package/dist/testing.js +82 -0
  63. package/dist/testing.js.map +1 -0
  64. package/dist/title.d.ts +7 -0
  65. package/dist/title.d.ts.map +1 -0
  66. package/dist/title.js +15 -0
  67. package/dist/title.js.map +1 -0
  68. package/dist/usage.d.ts +21 -0
  69. package/dist/usage.d.ts.map +1 -0
  70. package/dist/usage.js +35 -0
  71. package/dist/usage.js.map +1 -0
  72. package/dist/windowing.d.ts +38 -0
  73. package/dist/windowing.d.ts.map +1 -0
  74. package/dist/windowing.js +82 -0
  75. package/dist/windowing.js.map +1 -0
  76. package/package.json +78 -0
  77. package/src/artifact-writer.ts +114 -0
  78. package/src/attachments.ts +262 -0
  79. package/src/body.ts +236 -0
  80. package/src/client.ts +133 -0
  81. package/src/config.ts +376 -0
  82. package/src/errors.ts +80 -0
  83. package/src/feedback.ts +62 -0
  84. package/src/generation.ts +150 -0
  85. package/src/handler.ts +1164 -0
  86. package/src/index.ts +93 -0
  87. package/src/messages.ts +39 -0
  88. package/src/parts.ts +143 -0
  89. package/src/quota.ts +105 -0
  90. package/src/share.ts +103 -0
  91. package/src/testing.ts +150 -0
  92. package/src/title.ts +15 -0
  93. package/src/usage.ts +46 -0
  94. package/src/windowing.ts +110 -0
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The `streamText` options a product may set per turn: how the model
3
+ * samples (temperature, a token ceiling, a tool choice, a seed), none of
4
+ * which changes what settlement reads back. Written out as an allowlist
5
+ * rather than an `Omit<>` over the SDK's type, so an option a later SDK adds
6
+ * is not admitted silently.
7
+ *
8
+ * What the transport keeps, and why each one is not negotiable:
9
+ *
10
+ * `abortSignal` without `request.signal` an abandoned run bills in
11
+ * full and `onAbort` never fires.
12
+ * `timeout` a timeout lands on the error path, which releases
13
+ * the hold without charging tokens the provider has
14
+ * already produced. The route's deadline is
15
+ * `maxDuration`.
16
+ * `onFinish`, the transport captures `totalUsage` there; replacing
17
+ * `onEnd` it means every turn ends "stream ended without
18
+ * usage".
19
+ * `onAbort` settles from `sumStepUsage(steps)`.
20
+ * `onError` the failure path is `run.fail()` plus localised copy.
21
+ * `model` admission already priced the resolved `modelId`;
22
+ * another model bills one admission never saw.
23
+ * `system`, `prepareMessages` owns what the model is shown.
24
+ * `messages`,
25
+ * `prompt`,
26
+ * `instructions`
27
+ * `tools`, already seams on the agent, and the same object
28
+ * `activeTools` feeds `convertToModelMessages`; a second source
29
+ * desynchronises the two.
30
+ * `stopWhen` `stepCountIs(maxSteps)` must stay first and
31
+ * unremovable — an uncapped step count is an uncapped
32
+ * bill. `ResolvedAgent.stopWhen` appends to it.
33
+ * `_internal` the SDK's own test seam, not a product knob.
34
+ *
35
+ * Enforced three ways, because a cast defeats the type: the type itself,
36
+ * `pickGenerationOptions` copying only `GENERATION_KEYS` at runtime, and the
37
+ * handler spreading the result *first* so the transport's own keys win.
38
+ */
39
+ /**
40
+ * Every key of `ChatGenerationOptions`, as values.
41
+ *
42
+ * `satisfies` proves the array holds only real keys; `Exhaustive` below
43
+ * proves it holds all of them, so a field added to the interface
44
+ * without a line here is a compile error rather than an option that
45
+ * silently never reaches the model.
46
+ */
47
+ export const GENERATION_KEYS = [
48
+ "maxOutputTokens",
49
+ "temperature",
50
+ "topP",
51
+ "topK",
52
+ "presencePenalty",
53
+ "frequencyPenalty",
54
+ "stopSequences",
55
+ "seed",
56
+ "reasoning",
57
+ "maxRetries",
58
+ "headers",
59
+ "toolChoice",
60
+ "prepareStep",
61
+ "telemetry",
62
+ "experimental_transform",
63
+ "onStepEnd",
64
+ ];
65
+ // Stryker disable next-line BooleanLiteral: equivalent — the assertion is the type annotation, which `tsc` checks and the test runner's transform strips; the value itself is never read, so `false` changes nothing a test could observe.
66
+ const _exhaustive = true;
67
+ void _exhaustive;
68
+ /**
69
+ * The allowlisted options, copied by name.
70
+ *
71
+ * Absent keys produce no own property rather than an explicit
72
+ * `undefined`: the handler spreads the result into a call where a
73
+ * present-but-undefined key would override the SDK's own default.
74
+ */
75
+ export function pickGenerationOptions(options) {
76
+ if (!options)
77
+ return {};
78
+ const picked = {};
79
+ for (const key of GENERATION_KEYS) {
80
+ if (options[key] !== undefined)
81
+ picked[key] = options[key];
82
+ }
83
+ return picked;
84
+ }
85
+ //# sourceMappingURL=generation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generation.js","sourceRoot":"","sources":["../src/generation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AA4DH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,iBAAiB;IACjB,aAAa;IACb,MAAM;IACN,MAAM;IACN,iBAAiB;IACjB,kBAAkB;IAClB,eAAe;IACf,MAAM;IACN,WAAW;IACX,YAAY;IACZ,SAAS;IACT,YAAY;IACZ,aAAa;IACb,WAAW;IACX,wBAAwB;IACxB,WAAW;CACkD,CAAC;AAOhE,2OAA2O;AAC3O,MAAM,WAAW,GAAyC,IAAI,CAAC;AAC/D,KAAK,WAAW,CAAC;AAEjB;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAA0C;IAE1C,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QAClC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,MAAwC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The chat transport: one turn, from request to settled execution.
3
+ *
4
+ * onRequest → parse → authenticate → rate limit → load the row →
5
+ * resolveAgent → feature gate → model gate → create the row →
6
+ * prepareMessages → executions.begin() → streamText | streamTurn →
7
+ * settle → persist.
8
+ *
9
+ * Web `Request` in, `Response` out; request headers reach
10
+ * `requireWorkspace()` through `core/request-context`, never `next/*`.
11
+ *
12
+ * Entitlement is decided at `executions.begin()`, after the agent and
13
+ * model are resolved, so the hold matches what will actually run.
14
+ * Everything before it is cheaper and answers without opening an execution.
15
+ *
16
+ * Every terminal path settles exactly once: `complete()` is
17
+ * compare-and-swap in the boundary, so whichever of finish, abort or
18
+ * error gets there first wins and the others are no-ops.
19
+ */
20
+ import type { ChatServerConfig } from "./config.js";
21
+ export type ChatHandler = {
22
+ POST: (request: Request) => Promise<Response>;
23
+ DELETE: (request: Request) => Promise<Response>;
24
+ /** Stream resumption. Answers 204: no turn is resumable on this transport. */
25
+ GET: (request: Request) => Promise<Response>;
26
+ /** The CORS preflight, when `cors` is configured; 204 otherwise. */
27
+ OPTIONS: (request: Request) => Promise<Response>;
28
+ };
29
+ export declare function createChatHandler(config: ChatServerConfig): ChatHandler;
30
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAiDH,OAAO,KAAK,EAEV,gBAAgB,EAMjB,MAAM,UAAU,CAAC;AAgJlB,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9C,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChD,8EAA8E;IAC9E,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,oEAAoE;IACpE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAClD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW,CAu6BvE"}