slot-flight 0.1.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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +242 -0
  3. package/dist/adapters/openai.d.ts +49 -0
  4. package/dist/adapters/openai.d.ts.map +1 -0
  5. package/dist/adapters/openai.js +93 -0
  6. package/dist/adapters/openai.js.map +1 -0
  7. package/dist/adapters/stream.d.ts +10 -0
  8. package/dist/adapters/stream.d.ts.map +1 -0
  9. package/dist/adapters/stream.js +18 -0
  10. package/dist/adapters/stream.js.map +1 -0
  11. package/dist/adapters/vercel.d.ts +20 -0
  12. package/dist/adapters/vercel.d.ts.map +1 -0
  13. package/dist/adapters/vercel.js +67 -0
  14. package/dist/adapters/vercel.js.map +1 -0
  15. package/dist/core.d.ts +4 -0
  16. package/dist/core.d.ts.map +1 -0
  17. package/dist/core.js +3 -0
  18. package/dist/core.js.map +1 -0
  19. package/dist/engine.d.ts +14 -0
  20. package/dist/engine.d.ts.map +1 -0
  21. package/dist/engine.js +43 -0
  22. package/dist/engine.js.map +1 -0
  23. package/dist/errors.d.ts +23 -0
  24. package/dist/errors.d.ts.map +1 -0
  25. package/dist/errors.js +41 -0
  26. package/dist/errors.js.map +1 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +2 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/slot/execution/events.d.ts +15 -0
  32. package/dist/slot/execution/events.d.ts.map +1 -0
  33. package/dist/slot/execution/events.js +114 -0
  34. package/dist/slot/execution/events.js.map +1 -0
  35. package/dist/slot/execution/failures.d.ts +14 -0
  36. package/dist/slot/execution/failures.d.ts.map +1 -0
  37. package/dist/slot/execution/failures.js +71 -0
  38. package/dist/slot/execution/failures.js.map +1 -0
  39. package/dist/slot/execution/frame-request.d.ts +13 -0
  40. package/dist/slot/execution/frame-request.d.ts.map +1 -0
  41. package/dist/slot/execution/frame-request.js +45 -0
  42. package/dist/slot/execution/frame-request.js.map +1 -0
  43. package/dist/slot/execution/index.d.ts +4 -0
  44. package/dist/slot/execution/index.d.ts.map +1 -0
  45. package/dist/slot/execution/index.js +30 -0
  46. package/dist/slot/execution/index.js.map +1 -0
  47. package/dist/slot/execution/request.d.ts +3 -0
  48. package/dist/slot/execution/request.d.ts.map +1 -0
  49. package/dist/slot/execution/request.js +10 -0
  50. package/dist/slot/execution/request.js.map +1 -0
  51. package/dist/slot/execution/scope.d.ts +10 -0
  52. package/dist/slot/execution/scope.d.ts.map +1 -0
  53. package/dist/slot/execution/scope.js +85 -0
  54. package/dist/slot/execution/scope.js.map +1 -0
  55. package/dist/slot/execution/types.d.ts +21 -0
  56. package/dist/slot/execution/types.d.ts.map +1 -0
  57. package/dist/slot/execution/types.js +2 -0
  58. package/dist/slot/execution/types.js.map +1 -0
  59. package/dist/slot/frame/parser.d.ts +27 -0
  60. package/dist/slot/frame/parser.d.ts.map +1 -0
  61. package/dist/slot/frame/parser.js +143 -0
  62. package/dist/slot/frame/parser.js.map +1 -0
  63. package/dist/slot/frame/prompt.d.ts +4 -0
  64. package/dist/slot/frame/prompt.d.ts.map +1 -0
  65. package/dist/slot/frame/prompt.js +59 -0
  66. package/dist/slot/frame/prompt.js.map +1 -0
  67. package/dist/slot/frame/request.d.ts +5 -0
  68. package/dist/slot/frame/request.d.ts.map +1 -0
  69. package/dist/slot/frame/request.js +23 -0
  70. package/dist/slot/frame/request.js.map +1 -0
  71. package/dist/slot/index.d.ts +9 -0
  72. package/dist/slot/index.d.ts.map +1 -0
  73. package/dist/slot/index.js +9 -0
  74. package/dist/slot/index.js.map +1 -0
  75. package/dist/slot/object/definition.d.ts +12 -0
  76. package/dist/slot/object/definition.d.ts.map +1 -0
  77. package/dist/slot/object/definition.js +53 -0
  78. package/dist/slot/object/definition.js.map +1 -0
  79. package/dist/slot/object/projections.d.ts +6 -0
  80. package/dist/slot/object/projections.d.ts.map +1 -0
  81. package/dist/slot/object/projections.js +37 -0
  82. package/dist/slot/object/projections.js.map +1 -0
  83. package/dist/slot/object/run.d.ts +18 -0
  84. package/dist/slot/object/run.d.ts.map +1 -0
  85. package/dist/slot/object/run.js +94 -0
  86. package/dist/slot/object/run.js.map +1 -0
  87. package/dist/slot/object/stream.d.ts +34 -0
  88. package/dist/slot/object/stream.d.ts.map +1 -0
  89. package/dist/slot/object/stream.js +25 -0
  90. package/dist/slot/object/stream.js.map +1 -0
  91. package/dist/slot/object/web.d.ts +5 -0
  92. package/dist/slot/object/web.d.ts.map +1 -0
  93. package/dist/slot/object/web.js +107 -0
  94. package/dist/slot/object/web.js.map +1 -0
  95. package/dist/slot/path.d.ts +20 -0
  96. package/dist/slot/path.d.ts.map +1 -0
  97. package/dist/slot/path.js +125 -0
  98. package/dist/slot/path.js.map +1 -0
  99. package/dist/slot/plan.d.ts +7 -0
  100. package/dist/slot/plan.d.ts.map +1 -0
  101. package/dist/slot/plan.js +17 -0
  102. package/dist/slot/plan.js.map +1 -0
  103. package/dist/types.d.ts +94 -0
  104. package/dist/types.d.ts.map +1 -0
  105. package/dist/types.js +2 -0
  106. package/dist/types.js.map +1 -0
  107. package/package.json +70 -0
@@ -0,0 +1,25 @@
1
+ import { completedSlotIterator, partialObjectIterator } from "./projections.js";
2
+ import { SlotObjectRun } from "./run.js";
3
+ import { toReadableStream, toResponse } from "./web.js";
4
+ export function createSlotObjectStream(source, options = {}) {
5
+ const run = new SlotObjectRun(source, options.cancel);
6
+ return {
7
+ completedSlotStream: {
8
+ [Symbol.asyncIterator]: () => completedSlotIterator(run.events("completedSlotStream"))
9
+ },
10
+ get finalObject() {
11
+ return run.finalObject;
12
+ },
13
+ debug: {
14
+ partialObjectStream: {
15
+ [Symbol.asyncIterator]: () => partialObjectIterator(run.events("debug.partialObjectStream"))
16
+ },
17
+ slotEventStream: {
18
+ [Symbol.asyncIterator]: () => run.events("debug.slotEventStream")
19
+ },
20
+ toReadableStream: (options = {}) => toReadableStream(run.events("debug.toReadableStream"), options, () => run.cancel())
21
+ },
22
+ toResponse: (options = {}) => toResponse(run.events("toResponse"), options, () => run.cancel())
23
+ };
24
+ }
25
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/slot/object/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA0CxD,MAAM,UAAU,sBAAsB,CACpC,MAAsC,EACtC,UAAmC,EAAE;IAErC,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtD,OAAO;QACL,mBAAmB,EAAE;YACnB,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,CAC3B,qBAAqB,CAAI,GAAG,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;SAC9D;QACD,IAAI,WAAW;YACb,OAAO,GAAG,CAAC,WAAyB,CAAC;QACvC,CAAC;QACD,KAAK,EAAE;YACL,mBAAmB,EAAE;gBACnB,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,CAC3B,qBAAqB,CAAI,GAAG,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC;aACpE;YACD,eAAe,EAAE;gBACf,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,uBAAuB,CAAC;aAClE;YACD,gBAAgB,EAAE,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE,CACjC,gBAAgB,CAAI,GAAG,CAAC,MAAM,CAAC,wBAAwB,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CACtE,GAAG,CAAC,MAAM,EAAE,CACb;SACJ;QACD,UAAU,EAAE,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE,CAC3B,UAAU,CAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;KACvE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { SlotFlightEvent } from "../../types.js";
2
+ import type { SlotObjectReadableStreamOptions, SlotObjectResponseOptions } from "./stream.js";
3
+ export declare function toReadableStream<T>(events: AsyncIterable<SlotFlightEvent>, options: SlotObjectReadableStreamOptions, onCancel?: () => void): ReadableStream<Uint8Array>;
4
+ export declare function toResponse<T>(events: AsyncIterable<SlotFlightEvent>, options: SlotObjectResponseOptions, onCancel?: () => void): Response;
5
+ //# sourceMappingURL=web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../../src/slot/object/web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKtD,OAAO,KAAK,EACV,+BAA+B,EAC/B,yBAAyB,EAG1B,MAAM,aAAa,CAAC;AAErB,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,MAAM,EAAE,aAAa,CAAC,eAAe,CAAC,EACtC,OAAO,EAAE,+BAA+B,EACxC,QAAQ,CAAC,EAAE,MAAM,IAAI,GACpB,cAAc,CAAC,UAAU,CAAC,CAmC5B;AAED,wBAAgB,UAAU,CAAC,CAAC,EAC1B,MAAM,EAAE,aAAa,CAAC,eAAe,CAAC,EACtC,OAAO,EAAE,yBAAyB,EAClC,QAAQ,CAAC,EAAE,MAAM,IAAI,GACpB,QAAQ,CAqBV"}
@@ -0,0 +1,107 @@
1
+ import { completedEventIterator, partialObjectIterator } from "./projections.js";
2
+ export function toReadableStream(events, options, onCancel) {
3
+ const encoder = new TextEncoder();
4
+ const format = options.format ?? "sse";
5
+ const source = options.source ?? "completed";
6
+ let iterator;
7
+ let cancelled = false;
8
+ return new ReadableStream({
9
+ async start(controller) {
10
+ iterator = streamPayloads(events, source)[Symbol.asyncIterator]();
11
+ try {
12
+ while (!cancelled) {
13
+ const next = await iterator.next();
14
+ if (next.done) {
15
+ controller.close();
16
+ return;
17
+ }
18
+ const payload = next.value;
19
+ controller.enqueue(encoder.encode(formatPayload(payload, format)));
20
+ }
21
+ }
22
+ catch (error) {
23
+ if (!cancelled) {
24
+ controller.error(error);
25
+ }
26
+ }
27
+ },
28
+ async cancel() {
29
+ cancelled = true;
30
+ // Browser/client cancellation should abort the underlying model run, not
31
+ // just stop serializing bytes from this Response.
32
+ onCancel?.();
33
+ void iterator?.return?.();
34
+ }
35
+ });
36
+ }
37
+ export function toResponse(events, options, onCancel) {
38
+ const format = options.format ?? "sse";
39
+ const headers = new Headers(options.headers);
40
+ if (!headers.has("content-type")) {
41
+ headers.set("content-type", format === "sse"
42
+ ? "text/event-stream; charset=utf-8"
43
+ : "application/x-ndjson; charset=utf-8");
44
+ }
45
+ if (format === "sse" && !headers.has("cache-control")) {
46
+ headers.set("cache-control", "no-cache");
47
+ }
48
+ return new Response(toReadableStream(events, options, onCancel), {
49
+ status: options.status,
50
+ statusText: options.statusText,
51
+ headers
52
+ });
53
+ }
54
+ async function* streamPayloads(events, source) {
55
+ if (source === "partial") {
56
+ for await (const partial of partialObjectIterator(events)) {
57
+ yield { event: "partial", data: partial };
58
+ }
59
+ return;
60
+ }
61
+ if (source === "events") {
62
+ for await (const event of events) {
63
+ yield { event: event.type, data: serializeEvent(event) };
64
+ }
65
+ return;
66
+ }
67
+ for await (const event of completedEventIterator(events)) {
68
+ yield completedEventPayload(event);
69
+ }
70
+ }
71
+ function completedEventPayload(event) {
72
+ if (event.type === "slot-complete") {
73
+ return {
74
+ event: "slot",
75
+ data: {
76
+ slot: event.slot,
77
+ value: event.value,
78
+ state: event.state
79
+ }
80
+ };
81
+ }
82
+ if (event.type === "done") {
83
+ return { event: "done", data: { state: event.state } };
84
+ }
85
+ return { event: event.type, data: serializeEvent(event) };
86
+ }
87
+ function formatPayload(payload, format) {
88
+ if (format === "ndjson") {
89
+ return `${JSON.stringify({ type: payload.event, data: payload.data })}\n`;
90
+ }
91
+ return `event: ${payload.event}\ndata: ${JSON.stringify(payload.data)}\n\n`;
92
+ }
93
+ function serializeEvent(event) {
94
+ if (event.type === "slot-error" || event.type === "slot-retry") {
95
+ // Error objects lose useful fields through JSON.stringify; serialize the
96
+ // stable pieces clients can depend on.
97
+ return {
98
+ ...event,
99
+ error: {
100
+ name: event.error.name,
101
+ message: event.error.message
102
+ }
103
+ };
104
+ }
105
+ return event;
106
+ }
107
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../../src/slot/object/web.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAQ1B,MAAM,UAAU,gBAAgB,CAC9B,MAAsC,EACtC,OAAwC,EACxC,QAAqB;IAErB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;IACvC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,WAAW,CAAC;IAC7C,IAAI,QAAqE,CAAC;IAC1E,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,OAAO,IAAI,cAAc,CAAC;QACxB,KAAK,CAAC,KAAK,CAAC,UAAU;YACpB,QAAQ,GAAG,cAAc,CAAI,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YACrE,IAAI,CAAC;gBACH,OAAO,CAAC,SAAS,EAAE,CAAC;oBAClB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACnC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;wBACd,UAAU,CAAC,KAAK,EAAE,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ED,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED,SAAS,aAAa,CACpB,OAAyC,EACzC,MAA8B;IAE9B,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;QACxB,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC;IAC5E,CAAC;IAED,OAAO,UAAU,OAAO,CAAC,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;AAC9E,CAAC;AAED,SAAS,cAAc,CAAC,KAAsB;IAC5C,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC/D,yEAAyE;QACzE,uCAAuC;QACvC,OAAO;YACL,GAAG,KAAK;YACR,KAAK,EAAE;gBACL,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI;gBACtB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;aAC7B;SACF,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,20 @@
1
+ type TemplateToken = {
2
+ type: "property";
3
+ key: string;
4
+ } | {
5
+ type: "array-wildcard";
6
+ };
7
+ type ConcreteToken = {
8
+ type: "property";
9
+ key: string;
10
+ } | {
11
+ type: "index";
12
+ index: number;
13
+ };
14
+ export declare function parseSlotTemplate(path: string): TemplateToken[];
15
+ export declare function expandSlotPath(path: string, count?: number): string[];
16
+ export declare function parseConcretePath(path: string): ConcreteToken[];
17
+ export declare function concretePathToJsonPointer(path: string): string;
18
+ export declare function setPathValue(target: unknown, path: string, value: unknown): "add" | "replace";
19
+ export {};
20
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/slot/path.ts"],"names":[],"mappings":"AAEA,KAAK,aAAa,GACd;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAE/B,KAAK,aAAa,GACd;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CA+B/D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAmCrE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAgC/D;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM9D;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,KAAK,GAAG,SAAS,CA6DnB"}
@@ -0,0 +1,125 @@
1
+ import { SlotFlightConfigurationError } from "../errors.js";
2
+ export function parseSlotTemplate(path) {
3
+ if (path.trim() === "") {
4
+ throw new SlotFlightConfigurationError("Slot path cannot be empty.");
5
+ }
6
+ return path.split(".").flatMap((segment) => {
7
+ if (segment === "") {
8
+ throw new SlotFlightConfigurationError(`Invalid slot path "${path}".`);
9
+ }
10
+ if (segment.endsWith("[]")) {
11
+ const key = segment.slice(0, -2);
12
+ if (!key) {
13
+ throw new SlotFlightConfigurationError(`Invalid array segment "${segment}" in "${path}".`);
14
+ }
15
+ return [
16
+ { type: "property", key },
17
+ { type: "array-wildcard" }
18
+ ];
19
+ }
20
+ if (segment.includes("[") || segment.includes("]")) {
21
+ throw new SlotFlightConfigurationError(`Template path "${path}" must use [] wildcards, not concrete indexes.`);
22
+ }
23
+ return [{ type: "property", key: segment }];
24
+ });
25
+ }
26
+ export function expandSlotPath(path, count) {
27
+ const tokens = parseSlotTemplate(path);
28
+ const wildcardCount = tokens.filter((token) => token.type === "array-wildcard").length;
29
+ if (wildcardCount === 0) {
30
+ return [path];
31
+ }
32
+ if (wildcardCount > 1) {
33
+ throw new SlotFlightConfigurationError(`Slot path "${path}" has multiple [] wildcards. Define one repeated dimension per slot.`);
34
+ }
35
+ if (!Number.isInteger(count) || count === undefined || count < 0) {
36
+ throw new SlotFlightConfigurationError(`Slot path "${path}" requires a non-negative count.`);
37
+ }
38
+ const paths = [];
39
+ for (let index = 0; index < count; index += 1) {
40
+ paths.push(tokens
41
+ .map((token) => token.type === "property" ? token.key : `[${String(index)}]`)
42
+ .join(".")
43
+ .replaceAll(".[", "["));
44
+ }
45
+ return paths;
46
+ }
47
+ export function parseConcretePath(path) {
48
+ if (path.trim() === "") {
49
+ throw new SlotFlightConfigurationError("Concrete path cannot be empty.");
50
+ }
51
+ const tokens = [];
52
+ for (const segment of path.split(".")) {
53
+ if (segment === "") {
54
+ throw new SlotFlightConfigurationError(`Invalid concrete path "${path}".`);
55
+ }
56
+ const match = /^(?<key>[^[\]]+)(?<indexes>(\[\d+\])*)$/.exec(segment);
57
+ if (!match?.groups) {
58
+ throw new SlotFlightConfigurationError(`Invalid concrete path segment "${segment}".`);
59
+ }
60
+ tokens.push({ type: "property", key: match.groups.key });
61
+ const indexes = match.groups.indexes.match(/\[(\d+)\]/g) ?? [];
62
+ for (const rawIndex of indexes) {
63
+ tokens.push({
64
+ type: "index",
65
+ index: Number(rawIndex.slice(1, -1))
66
+ });
67
+ }
68
+ }
69
+ return tokens;
70
+ }
71
+ export function concretePathToJsonPointer(path) {
72
+ return parseConcretePath(path)
73
+ .map((token) => token.type === "property" ? escapePointer(token.key) : String(token.index))
74
+ .reduce((pointer, segment) => `${pointer}/${segment}`, "");
75
+ }
76
+ export function setPathValue(target, path, value) {
77
+ if (!isRecord(target)) {
78
+ throw new SlotFlightConfigurationError("JSON state root must be an object.");
79
+ }
80
+ const tokens = parseConcretePath(path);
81
+ let current = target;
82
+ for (let index = 0; index < tokens.length; index += 1) {
83
+ const token = tokens[index];
84
+ const isLast = index === tokens.length - 1;
85
+ if (token.type === "property") {
86
+ if (!isRecord(current)) {
87
+ throw new SlotFlightConfigurationError(`Cannot set property "${token.key}" in "${path}".`);
88
+ }
89
+ if (isLast) {
90
+ const operation = Object.hasOwn(current, token.key) ? "replace" : "add";
91
+ current[token.key] = value;
92
+ return operation;
93
+ }
94
+ if (!Object.hasOwn(current, token.key) || current[token.key] == null) {
95
+ // The server owns JSON assembly, so missing containers are created from
96
+ // the next token instead of relying on model-emitted structure.
97
+ current[token.key] = tokens[index + 1]?.type === "index" ? [] : {};
98
+ }
99
+ current = current[token.key];
100
+ continue;
101
+ }
102
+ if (!Array.isArray(current)) {
103
+ throw new SlotFlightConfigurationError(`Cannot set array index ${token.index} in "${path}".`);
104
+ }
105
+ if (isLast) {
106
+ const operation = token.index in current ? "replace" : "add";
107
+ current[token.index] = value;
108
+ return operation;
109
+ }
110
+ if (current[token.index] == null) {
111
+ // Preserve sparse array semantics while still creating nested containers
112
+ // when a later slot targets a deeper path.
113
+ current[token.index] = tokens[index + 1]?.type === "index" ? [] : {};
114
+ }
115
+ current = current[token.index];
116
+ }
117
+ throw new SlotFlightConfigurationError(`Cannot set value for path "${path}".`);
118
+ }
119
+ function escapePointer(segment) {
120
+ return segment.replaceAll("~", "~0").replaceAll("/", "~1");
121
+ }
122
+ function isRecord(value) {
123
+ return typeof value === "object" && value !== null && !Array.isArray(value);
124
+ }
125
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/slot/path.ts"],"names":[],"mappings":"AAAA,OAAO,EA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IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { SlotDefinition } from "../types.js";
2
+ export interface CompiledSlot {
3
+ definition: SlotDefinition;
4
+ path: string;
5
+ }
6
+ export declare function compileSlotPlan(definitions: SlotDefinition[]): CompiledSlot[];
7
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../src/slot/plan.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,cAAc,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,YAAY,EAAE,CAiB7E"}
@@ -0,0 +1,17 @@
1
+ import { SlotFlightConfigurationError } from "../errors.js";
2
+ import { expandSlotPath } from "./path.js";
3
+ export function compileSlotPlan(definitions) {
4
+ const slots = [];
5
+ const seen = new Set();
6
+ for (const definition of definitions) {
7
+ for (const path of expandSlotPath(definition.path, definition.count)) {
8
+ if (seen.has(path)) {
9
+ throw new SlotFlightConfigurationError(`Duplicate slot path "${path}".`);
10
+ }
11
+ seen.add(path);
12
+ slots.push({ definition, path });
13
+ }
14
+ }
15
+ return slots;
16
+ }
17
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/slot/plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAO3C,MAAM,UAAU,eAAe,CAAC,WAA6B;IAC3D,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACrE,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACnB,MAAM,IAAI,4BAA4B,CACpC,wBAAwB,IAAI,IAAI,CACjC,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,94 @@
1
+ import type { z } from "zod";
2
+ export type MaybePromise<T> = T | Promise<T>;
3
+ export type SlotFlightEvent = {
4
+ type: "slot-start";
5
+ slot: string;
6
+ attempt: number;
7
+ state: unknown;
8
+ } | {
9
+ type: "slot-delta";
10
+ slot: string;
11
+ attempt: number;
12
+ delta: string;
13
+ value: string;
14
+ state: unknown;
15
+ } | {
16
+ type: "slot-complete";
17
+ slot: string;
18
+ attempt: number;
19
+ value: unknown;
20
+ state: unknown;
21
+ } | {
22
+ type: "slot-retry";
23
+ slot: string;
24
+ attempt: number;
25
+ error: Error;
26
+ state: unknown;
27
+ } | {
28
+ type: "slot-error";
29
+ slot: string;
30
+ attempt: number;
31
+ error: Error;
32
+ state: unknown;
33
+ } | {
34
+ type: "done";
35
+ state: unknown;
36
+ };
37
+ export interface SlotDefinition<TValue = unknown> {
38
+ /**
39
+ * Slot path inside the server-owned JSON document.
40
+ *
41
+ * Examples: "title", "summary", "tags[]", "sections[].heading".
42
+ * Paths with [] require count, which expands them into concrete item paths.
43
+ */
44
+ path: string;
45
+ prompt?: string | ((slot: SlotFrameRequest) => string);
46
+ schema: z.ZodType<TValue>;
47
+ mode?: "text" | "json";
48
+ count?: number;
49
+ /**
50
+ * Overrides the engine retry count for this slot only.
51
+ *
52
+ * Retry is scoped to slot parsing, validation, and recoverable protocol
53
+ * failures. Provider-level retry, backoff, and rate limiting belong outside
54
+ * slot-flight.
55
+ */
56
+ maxRetries?: number;
57
+ }
58
+ export interface SlotFrameRequest {
59
+ id: string;
60
+ path: string;
61
+ templatePath: string;
62
+ prompt: string;
63
+ attempt: number;
64
+ mode: "text" | "json";
65
+ }
66
+ export interface SlotFlightRequest {
67
+ prompt: string;
68
+ slots: SlotFrameRequest[];
69
+ attempt: number;
70
+ signal: AbortSignal;
71
+ }
72
+ export type SlotFlightPromptRequest = Omit<SlotFlightRequest, "signal">;
73
+ export type SlotFlightPrompt = string | ((request: SlotFlightPromptRequest) => string);
74
+ export type SlotGenerator = (request: SlotFlightRequest) => AsyncIterable<string> | Promise<AsyncIterable<string>>;
75
+ export interface SlotFlightOptions<TSchema extends z.ZodTypeAny> {
76
+ schema: TSchema;
77
+ slots: SlotDefinition[];
78
+ generate: SlotGenerator;
79
+ prompt?: SlotFlightPrompt;
80
+ /**
81
+ * Number of validation/parsing retries per failed slot.
82
+ *
83
+ * This does not retry transport errors as a provider policy; it only retries
84
+ * the slot units the engine can prove failed or recoverably malformed.
85
+ */
86
+ maxRetries?: number;
87
+ }
88
+ export interface SlotFlightRunOptions {
89
+ signal?: AbortSignal;
90
+ }
91
+ export interface SlotFlightResult<T> {
92
+ state: T;
93
+ }
94
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,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,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;AAExE,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,CAAC,CAAC,OAAO,EAAE,uBAAuB,KAAK,MAAM,CAAC,CAAC;AAEnD,MAAM,MAAM,aAAa,GAAG,CAC1B,OAAO,EAAE,iBAAiB,KACvB,aAAa,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AAE5D,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,CAAC,CAAC,UAAU;IAC7D,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,KAAK,EAAE,CAAC,CAAC;CACV"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "slot-flight",
3
+ "version": "0.1.0",
4
+ "description": "Slot-wise LLM generation and server-owned JSON assembly for TypeScript.",
5
+ "packageManager": "bun@1.3.14",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./core": {
15
+ "types": "./dist/core.d.ts",
16
+ "import": "./dist/core.js"
17
+ },
18
+ "./adapters/openai": {
19
+ "types": "./dist/adapters/openai.d.ts",
20
+ "import": "./dist/adapters/openai.js"
21
+ },
22
+ "./adapters/stream": {
23
+ "types": "./dist/adapters/stream.d.ts",
24
+ "import": "./dist/adapters/stream.js"
25
+ },
26
+ "./adapters/vercel": {
27
+ "types": "./dist/adapters/vercel.d.ts",
28
+ "import": "./dist/adapters/vercel.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist/**/*"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "bench:leak": "bun --expose-gc bench/leak.ts",
39
+ "bench:perf": "bun bench/perf.ts",
40
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
41
+ "check": "biome check .",
42
+ "compare:ollama": "bun scripts/compare-ollama.ts",
43
+ "example:openai": "bun examples/openai-compatible.ts",
44
+ "example:vercel": "bun examples/vercel-ai-sdk.ts",
45
+ "fix": "biome check --write .",
46
+ "format": "biome format --write .",
47
+ "lint": "biome lint .",
48
+ "test": "bun test",
49
+ "typecheck": "tsc -p tsconfig.json --noEmit"
50
+ },
51
+ "keywords": [
52
+ "llm",
53
+ "json",
54
+ "streaming",
55
+ "zod",
56
+ "slot-generation"
57
+ ],
58
+ "license": "MIT",
59
+ "dependencies": {
60
+ "zod": "^3.25.67"
61
+ },
62
+ "devDependencies": {
63
+ "@ai-sdk/openai": "^4.0.2",
64
+ "@biomejs/biome": "^2.5.1",
65
+ "@types/bun": "latest",
66
+ "ai": "^7.0.4",
67
+ "openai": "^6.45.0",
68
+ "typescript": "^5.8.3"
69
+ }
70
+ }