@jini-ai/integrations 0.4.1 → 0.4.3

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 (146) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/api-connections/access-token.d.ts +9 -0
  3. package/dist/api-connections/access-token.js +92 -0
  4. package/dist/api-connections/account-actions.d.ts +40 -0
  5. package/dist/api-connections/account-actions.js +110 -0
  6. package/dist/api-connections/attempt-state.d.ts +28 -0
  7. package/dist/api-connections/attempt-state.js +73 -0
  8. package/dist/api-connections/authorization.d.ts +45 -0
  9. package/dist/api-connections/authorization.js +120 -0
  10. package/dist/api-connections/deps.d.ts +41 -0
  11. package/dist/api-connections/deps.js +13 -0
  12. package/dist/api-connections/descriptor.d.ts +6 -0
  13. package/dist/api-connections/descriptor.js +111 -0
  14. package/dist/api-connections/errors.d.ts +23 -0
  15. package/dist/api-connections/errors.js +24 -0
  16. package/dist/api-connections/finish-authorization.d.ts +24 -0
  17. package/dist/api-connections/finish-authorization.js +117 -0
  18. package/dist/api-connections/index.d.ts +18 -0
  19. package/dist/api-connections/index.js +10 -0
  20. package/dist/api-connections/install-credential.d.ts +19 -0
  21. package/dist/api-connections/install-credential.js +12 -0
  22. package/dist/api-connections/keys.d.ts +27 -0
  23. package/dist/api-connections/keys.js +22 -0
  24. package/dist/api-connections/ports.d.ts +73 -0
  25. package/dist/api-connections/ports.js +2 -0
  26. package/dist/api-connections/records.d.ts +27 -0
  27. package/dist/api-connections/records.js +52 -0
  28. package/dist/api-connections/request-checks.d.ts +18 -0
  29. package/dist/api-connections/request-checks.js +67 -0
  30. package/dist/api-connections/service.d.ts +25 -0
  31. package/dist/api-connections/service.js +26 -0
  32. package/dist/api-connections/status.d.ts +28 -0
  33. package/dist/api-connections/status.js +36 -0
  34. package/dist/api-connections/token-store/errors.d.ts +20 -0
  35. package/dist/api-connections/token-store/errors.js +38 -0
  36. package/dist/api-connections/token-store/index.d.ts +6 -0
  37. package/dist/api-connections/token-store/index.js +6 -0
  38. package/dist/api-connections/token-store/record.d.ts +69 -0
  39. package/dist/api-connections/token-store/record.js +97 -0
  40. package/dist/api-connections/token-store/vault-token-store.d.ts +26 -0
  41. package/dist/api-connections/token-store/vault-token-store.js +215 -0
  42. package/dist/api-connections/types.d.ts +101 -0
  43. package/dist/api-connections/types.js +9 -0
  44. package/dist/credentialed-http/auth-schemes.js +8 -4
  45. package/dist/credentialed-http/credentialed-request.js +47 -77
  46. package/dist/credentialed-http/response-redaction.d.ts +5 -0
  47. package/dist/credentialed-http/response-redaction.js +62 -0
  48. package/dist/media-providers/catalog.d.ts +3 -1
  49. package/dist/media-providers/catalog.js +3 -1
  50. package/dist/media-providers/dispatch/async-operation-store.d.ts +31 -0
  51. package/dist/media-providers/dispatch/async-operation-store.js +75 -37
  52. package/dist/media-providers/dispatch/builtin-vendors.d.ts +1 -1
  53. package/dist/media-providers/dispatch/context.js +10 -2
  54. package/dist/media-providers/dispatch/credentials.d.ts +1 -1
  55. package/dist/media-providers/dispatch/credentials.js +3 -3
  56. package/dist/media-providers/dispatch/engine.d.ts +6 -3
  57. package/dist/media-providers/dispatch/engine.js +102 -109
  58. package/dist/media-providers/dispatch/index.d.ts +4 -2
  59. package/dist/media-providers/dispatch/index.js +3 -1
  60. package/dist/media-providers/dispatch/media-provider-registry.d.ts +62 -0
  61. package/dist/media-providers/dispatch/media-provider-registry.js +141 -0
  62. package/dist/media-providers/dispatch/node.d.ts +13 -0
  63. package/dist/media-providers/dispatch/node.js +24 -0
  64. package/dist/media-providers/dispatch/openai-compatible.d.ts +1 -1
  65. package/dist/media-providers/dispatch/openai-compatible.js +90 -87
  66. package/dist/media-providers/dispatch/operation-runtime.js +116 -89
  67. package/dist/media-providers/dispatch/outbound.d.ts +8 -4
  68. package/dist/media-providers/dispatch/outbound.js +27 -26
  69. package/dist/media-providers/dispatch/providers/aihubmix.d.ts +1 -1
  70. package/dist/media-providers/dispatch/providers/aihubmix.js +61 -56
  71. package/dist/media-providers/dispatch/providers/custom-image.d.ts +1 -1
  72. package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +1 -1
  73. package/dist/media-providers/dispatch/providers/fishaudio.d.ts +1 -1
  74. package/dist/media-providers/dispatch/providers/grok.d.ts +1 -1
  75. package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
  76. package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +53 -49
  77. package/dist/media-providers/dispatch/providers/imagerouter.d.ts +1 -1
  78. package/dist/media-providers/dispatch/providers/imagerouter.js +11 -24
  79. package/dist/media-providers/dispatch/providers/minimax.d.ts +1 -1
  80. package/dist/media-providers/dispatch/providers/nanobanana.d.ts +1 -1
  81. package/dist/media-providers/dispatch/providers/nanobanana.js +22 -30
  82. package/dist/media-providers/dispatch/providers/openai.d.ts +1 -1
  83. package/dist/media-providers/dispatch/providers/openai.js +51 -47
  84. package/dist/media-providers/dispatch/providers/openrouter.d.ts +1 -1
  85. package/dist/media-providers/dispatch/providers/openrouter.js +52 -37
  86. package/dist/media-providers/dispatch/providers/senseaudio.d.ts +1 -1
  87. package/dist/media-providers/dispatch/providers/senseaudio.js +47 -28
  88. package/dist/media-providers/dispatch/providers/volcengine.d.ts +1 -1
  89. package/dist/media-providers/dispatch/response-parsers.js +37 -21
  90. package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +35 -1
  91. package/dist/media-providers/dispatch/sqlite-async-operation-store.js +13 -32
  92. package/dist/media-providers/dispatch/ssrf-guard.d.ts +3 -2
  93. package/dist/media-providers/dispatch/ssrf-guard.js +6 -5
  94. package/dist/media-providers/dispatch/types.d.ts +76 -2
  95. package/dist/media-providers/dispatch/vendor-adapter.d.ts +2 -43
  96. package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
  97. package/dist/media-providers/dispatch/vendor-registry-core.d.ts +24 -0
  98. package/dist/media-providers/dispatch/vendor-registry-core.js +34 -0
  99. package/dist/media-providers/dispatch/vendor-registry.d.ts +10 -36
  100. package/dist/media-providers/dispatch/vendor-registry.js +14 -42
  101. package/dist/media-providers/policy.js +25 -17
  102. package/dist/media-providers/providers.d.ts +39 -0
  103. package/dist/media-providers/providers.js +50 -18
  104. package/dist/media-providers/sqlite-driver.adapter.d.ts +4 -0
  105. package/dist/media-providers/sqlite-driver.adapter.js +5 -0
  106. package/dist/media-providers/sqlite-task-store.d.ts +50 -2
  107. package/dist/media-providers/sqlite-task-store.js +20 -84
  108. package/dist/media-providers/staging.js +77 -58
  109. package/dist/media-providers/task-lifecycle.d.ts +33 -0
  110. package/dist/media-providers/task-lifecycle.js +124 -0
  111. package/dist/media-providers/task-store.js +8 -86
  112. package/dist/media-providers/ui-defaults.d.ts +10 -0
  113. package/dist/media-providers/ui-defaults.js +167 -0
  114. package/dist/media-providers/video-request.js +112 -90
  115. package/dist/webhooks/delivery.d.ts +14 -0
  116. package/dist/webhooks/delivery.js +41 -10
  117. package/dist/webhooks/index.d.ts +1 -0
  118. package/dist/webhooks/index.js +1 -0
  119. package/dist/webhooks/ports.d.ts +23 -0
  120. package/dist/webhooks/subscriptions.d.ts +1 -1
  121. package/dist/webhooks/subscriptions.js +5 -1
  122. package/dist/webhooks/worker.d.ts +83 -0
  123. package/dist/webhooks/worker.js +105 -0
  124. package/package.json +35 -7
  125. package/dist/composio/bounded-data.d.ts +0 -36
  126. package/dist/composio/bounded-data.js +0 -181
  127. package/dist/composio/catalog.d.ts +0 -147
  128. package/dist/composio/catalog.js +0 -126
  129. package/dist/composio/composio-config.d.ts +0 -42
  130. package/dist/composio/composio-config.js +0 -145
  131. package/dist/composio/composio-descriptions.d.ts +0 -16
  132. package/dist/composio/composio-descriptions.js +0 -766
  133. package/dist/composio/composio.d.ts +0 -364
  134. package/dist/composio/composio.js +0 -1902
  135. package/dist/composio/errors.d.ts +0 -15
  136. package/dist/composio/errors.js +0 -16
  137. package/dist/composio/file-lock.d.ts +0 -13
  138. package/dist/composio/file-lock.js +0 -92
  139. package/dist/composio/index.d.ts +0 -18
  140. package/dist/composio/index.js +0 -7
  141. package/dist/composio/json-schema.d.ts +0 -93
  142. package/dist/composio/json-schema.js +0 -498
  143. package/dist/composio/output-protection.d.ts +0 -32
  144. package/dist/composio/output-protection.js +0 -105
  145. package/dist/composio/service.d.ts +0 -181
  146. package/dist/composio/service.js +0 -758
@@ -58,6 +58,77 @@ async function pruneStagedAttachments(stagingDir, maxAgeMs) {
58
58
  }
59
59
  }));
60
60
  }
61
+ // Fail closed, not open: an explicitly-supplied uploadRoot that doesn't
62
+ // resolve is a caller configuration error, not an "unrestricted" signal
63
+ // (SEC-RB-003 — the prior behavior collapsed "no uploadRoot" and
64
+ // "unresolvable uploadRoot" into the same no-restriction case, letting
65
+ // any host-readable file be staged when uploadRoot merely failed to
66
+ // resolve). Omitting uploadRoot entirely is still allowed, but then only
67
+ // paths already inside `cwd` can be staged — nothing outside `cwd` can
68
+ // be copied in without a resolvable uploadRoot to authorize it.
69
+ async function resolveUploadRoot(uploadRoot) {
70
+ if (uploadRoot == null)
71
+ return null;
72
+ try {
73
+ return await fs.promises.realpath(uploadRoot);
74
+ }
75
+ catch (error) {
76
+ throw new Error(`attachment staging: uploadRoot ${JSON.stringify(uploadRoot)} could not be resolved: ${error.message}`);
77
+ }
78
+ }
79
+ /** Creates `stagingDir`, refuses a symlinked one, and prunes stale entries. */
80
+ async function prepareStagingDir(stagingDir, maxAgeMs) {
81
+ await fs.promises.mkdir(stagingDir, { recursive: true });
82
+ // The staging directory is a destination this component writes into
83
+ // and later prunes/deletes from — refuse to operate through a symlink
84
+ // here, since a pre-planted symlink would redirect writes/deletes
85
+ // outside `root` (SEC-RB-003).
86
+ const stagingDirLstat = await fs.promises.lstat(stagingDir);
87
+ if (stagingDirLstat.isSymbolicLink()) {
88
+ throw new Error(`attachment staging: staging directory ${stagingDir} is a symlink, refusing to use it`);
89
+ }
90
+ await pruneStagedAttachments(stagingDir, maxAgeMs);
91
+ }
92
+ /**
93
+ * Stages one already-validated, non-blank path. Returns the path to submit,
94
+ * or null when the file is advisory-skippable (not a file, outside
95
+ * uploadRoot, too large). Throws `MissingUploadRootError` for an outside-cwd
96
+ * file with no uploadRoot; any other error is the caller's to swallow.
97
+ */
98
+ async function stageOne(inputPath, ctx) {
99
+ const real = await fs.promises.realpath(path.resolve(inputPath));
100
+ const stat = await fs.promises.stat(real);
101
+ if (!stat.isFile())
102
+ return null;
103
+ if (isWithinRoot(ctx.rootReal, real))
104
+ return real;
105
+ // Outside cwd: this is the "copy an external file into staging"
106
+ // path, which requires an authorized uploadRoot — deny by default.
107
+ if (ctx.uploadRootReal == null) {
108
+ throw new MissingUploadRootError('attachment staging: files outside cwd require an uploadRoot');
109
+ }
110
+ if (!isWithinRoot(ctx.uploadRootReal, real))
111
+ return null;
112
+ if (stat.size > ctx.maxBytesPerFile)
113
+ return null;
114
+ const destination = path.join(ctx.stagingDir, `${randomUUID()}-${path.basename(real)}`);
115
+ await fs.promises.copyFile(real, destination);
116
+ return destination;
117
+ }
118
+ /** `stageOne` with the advisory-input policy: malformed or missing files are skipped, authorization failures escape. */
119
+ async function stageOneAdvisory(inputPath, ctx) {
120
+ if (typeof inputPath !== 'string' || inputPath.trim().length === 0)
121
+ return null;
122
+ try {
123
+ return await stageOne(inputPath, ctx);
124
+ }
125
+ catch (error) {
126
+ if (error instanceof MissingUploadRootError)
127
+ throw error;
128
+ // Ignore malformed or missing files; attachments are advisory input.
129
+ return null;
130
+ }
131
+ }
61
132
  /** Creates a filesystem-backed `AttachmentStaging` rooted at `cwd`. */
62
133
  export function createFsAttachmentStaging({ cwd }, options = {}) {
63
134
  const stagingDirName = options.stagingDirName ?? DEFAULT_STAGING_DIRNAME;
@@ -74,33 +145,8 @@ export function createFsAttachmentStaging({ cwd }, options = {}) {
74
145
  if (imagePaths.length > maxItems) {
75
146
  throw new Error(`attachment staging: ${imagePaths.length} paths exceeds the ${maxItems}-item limit`);
76
147
  }
77
- // Fail closed, not open: an explicitly-supplied uploadRoot that doesn't
78
- // resolve is a caller configuration error, not an "unrestricted" signal
79
- // (SEC-RB-003 — the prior behavior collapsed "no uploadRoot" and
80
- // "unresolvable uploadRoot" into the same no-restriction case, letting
81
- // any host-readable file be staged when uploadRoot merely failed to
82
- // resolve). Omitting uploadRoot entirely is still allowed, but then only
83
- // paths already inside `cwd` can be staged — nothing outside `cwd` can
84
- // be copied in without a resolvable uploadRoot to authorize it.
85
- let uploadRootReal = null;
86
- if (uploadRoot != null) {
87
- try {
88
- uploadRootReal = await fs.promises.realpath(uploadRoot);
89
- }
90
- catch (error) {
91
- throw new Error(`attachment staging: uploadRoot ${JSON.stringify(uploadRoot)} could not be resolved: ${error.message}`);
92
- }
93
- }
94
- await fs.promises.mkdir(stagingDir, { recursive: true });
95
- // The staging directory is a destination this component writes into
96
- // and later prunes/deletes from — refuse to operate through a symlink
97
- // here, since a pre-planted symlink would redirect writes/deletes
98
- // outside `root` (SEC-RB-003).
99
- const stagingDirLstat = await fs.promises.lstat(stagingDir);
100
- if (stagingDirLstat.isSymbolicLink()) {
101
- throw new Error(`attachment staging: staging directory ${stagingDir} is a symlink, refusing to use it`);
102
- }
103
- await pruneStagedAttachments(stagingDir, maxAgeMs);
148
+ const uploadRootReal = await resolveUploadRoot(uploadRoot);
149
+ await prepareStagingDir(stagingDir, maxAgeMs);
104
150
  // `root` is guaranteed to exist at this point (the recursive mkdir above
105
151
  // created it if it didn't already). Resolve its real path once so the
106
152
  // "already inside cwd" check below compares like-for-like against
@@ -109,39 +155,12 @@ export function createFsAttachmentStaging({ cwd }, options = {}) {
109
155
  // prefix (e.g. macOS's /tmp -> /private/tmp, /var -> /private/var),
110
156
  // causing an unnecessary copy instead of returning the path as-is.
111
157
  const rootReal = await fs.promises.realpath(root).catch(() => root);
158
+ const ctx = { rootReal, uploadRootReal, stagingDir, maxBytesPerFile };
112
159
  const staged = [];
113
160
  for (const inputPath of imagePaths) {
114
- if (typeof inputPath !== 'string' || inputPath.trim().length === 0)
115
- continue;
116
- try {
117
- const resolved = path.resolve(inputPath);
118
- const real = await fs.promises.realpath(resolved);
119
- const stat = await fs.promises.stat(real);
120
- if (!stat.isFile())
121
- continue;
122
- if (isWithinRoot(rootReal, real)) {
123
- staged.push(real);
124
- continue;
125
- }
126
- // Outside cwd: this is the "copy an external file into staging"
127
- // path, which requires an authorized uploadRoot — deny by default.
128
- if (uploadRootReal == null) {
129
- throw new MissingUploadRootError('attachment staging: files outside cwd require an uploadRoot');
130
- }
131
- if (!isWithinRoot(uploadRootReal, real))
132
- continue;
133
- if (stat.size > maxBytesPerFile)
134
- continue;
135
- const basename = path.basename(real);
136
- const destination = path.join(stagingDir, `${randomUUID()}-${basename}`);
137
- await fs.promises.copyFile(real, destination);
138
- staged.push(destination);
139
- }
140
- catch (error) {
141
- if (error instanceof MissingUploadRootError)
142
- throw error;
143
- // Ignore malformed or missing files; attachments are advisory input.
144
- }
161
+ const result = await stageOneAdvisory(inputPath, ctx);
162
+ if (result !== null)
163
+ staged.push(result);
145
164
  }
146
165
  return staged;
147
166
  },
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Storage-agnostic `MediaTask` lifecycle rules shared by every
3
+ * `MediaTaskStore` adapter (`createInMemoryMediaTaskStore` in
4
+ * `task-store.ts`, `createSqliteMediaTaskStore` in `sqlite-task-store.ts`).
5
+ * Each adapter used to carry its own copy of the status sets, the
6
+ * transition graph and the create/patch/reconcile row arithmetic; keeping a
7
+ * single copy here means the two adapters cannot drift apart. Internal to
8
+ * the package (not re-exported from the barrel).
9
+ */
10
+ import type { MediaTask, MediaTaskCreateInput, MediaTaskPatch, MediaTaskStatus } from './task-store.js';
11
+ export declare const TERMINAL_STATUSES: ReadonlySet<MediaTaskStatus>;
12
+ /** Builds the stored row for `create()`; the caller checks for a duplicate id first. */
13
+ export declare function buildNewTask(input: MediaTaskCreateInput, now: number): MediaTask;
14
+ /** Validates `patch` against `existing` (status enum, then transition graph) and returns the next stored row. */
15
+ export declare function applyTaskPatch(existing: MediaTask, patch: MediaTaskPatch, now: number): MediaTask;
16
+ export declare function assertValidTerminalTtl(terminalTtlMs: number): void;
17
+ /** What boot-time reconciliation does to one stored task. */
18
+ export type ReconcileAction = {
19
+ readonly kind: 'interrupt';
20
+ readonly next: MediaTask;
21
+ } | {
22
+ readonly kind: 'delete';
23
+ } | {
24
+ readonly kind: 'keep';
25
+ };
26
+ /**
27
+ * A restart mid-flight has no way to resume a `queued`/`running` task, so it
28
+ * becomes `interrupted` (keeping an already-set `endedAt`); a terminal task
29
+ * whose `endedAt` (or, failing that, `updatedAt`) is older than `cutoff` is
30
+ * deleted. A task interrupted in this pass is never also deleted in it.
31
+ */
32
+ export declare function reconcileAction(task: MediaTask, now: number, cutoff: number): ReconcileAction;
33
+ //# sourceMappingURL=task-lifecycle.d.ts.map
@@ -0,0 +1,124 @@
1
+ // CR-013: `assertValidStatus` alone only proves enum membership, not that a
2
+ // transition is legal — it allowed e.g. `done` -> `running`. This is the
3
+ // actual lifecycle graph the store's own docs claim
4
+ // (queued -> running -> done|failed|interrupted); same-state is included so
5
+ // a caller can `update()` progress/file without also having to re-derive the
6
+ // current status, but nothing can leave a terminal state once reached.
7
+ const ALLOWED_TRANSITIONS = {
8
+ // `queued` may go straight to a terminal state too (a caller isn't
9
+ // required to make a separate "now running" update before finishing).
10
+ queued: new Set(['queued', 'running', 'done', 'failed', 'interrupted']),
11
+ running: new Set(['running', 'done', 'failed', 'interrupted']),
12
+ done: new Set(['done']),
13
+ failed: new Set(['failed']),
14
+ interrupted: new Set(['interrupted']),
15
+ };
16
+ const VALID_STATUSES = new Set(Object.keys(ALLOWED_TRANSITIONS));
17
+ export const TERMINAL_STATUSES = new Set(['done', 'failed', 'interrupted']);
18
+ const INTERRUPTED_ERROR = {
19
+ message: 'media task interrupted by daemon restart',
20
+ code: 'DAEMON_RESTART',
21
+ };
22
+ function assertValidStatus(status) {
23
+ if (!VALID_STATUSES.has(status)) {
24
+ throw new RangeError(`Invalid media task status: "${status}"`);
25
+ }
26
+ }
27
+ function snapshotFile(file) {
28
+ return file == null ? null : structuredClone(file);
29
+ }
30
+ function snapshotError(error) {
31
+ return error == null ? null : { ...error };
32
+ }
33
+ /**
34
+ * `surface`/`model` are conditionally spread — this package's
35
+ * `exactOptionalPropertyTypes: true` tsconfig rejects assigning `undefined`
36
+ * to an optional field, so a task without a `surface`/`model` has no key at
37
+ * all, not a key set to `undefined`.
38
+ */
39
+ function labelFields(surface, model) {
40
+ return {
41
+ ...(surface !== undefined ? { surface } : {}),
42
+ ...(model !== undefined ? { model } : {}),
43
+ };
44
+ }
45
+ /** Builds the stored row for `create()`; the caller checks for a duplicate id first. */
46
+ export function buildNewTask(input, now) {
47
+ const status = input.status ?? 'queued';
48
+ assertValidStatus(status);
49
+ return {
50
+ id: input.id,
51
+ ownerRef: input.ownerRef,
52
+ status,
53
+ progress: input.progress ? [...input.progress] : [],
54
+ file: snapshotFile(input.file),
55
+ error: snapshotError(input.error),
56
+ startedAt: input.startedAt ?? now,
57
+ endedAt: null,
58
+ createdAt: now,
59
+ updatedAt: now,
60
+ ...labelFields(input.surface, input.model),
61
+ };
62
+ }
63
+ /** A key present in the patch (even as `null`/`undefined`) replaces the stored value; an absent key keeps it. */
64
+ function patchedLabels(existing, patch) {
65
+ const surface = 'surface' in patch ? (patch.surface ?? undefined) : existing.surface;
66
+ const model = 'model' in patch ? (patch.model ?? undefined) : existing.model;
67
+ return labelFields(surface, model);
68
+ }
69
+ function patchedPayload(existing, patch) {
70
+ return {
71
+ progress: patch.progress ? [...patch.progress] : existing.progress,
72
+ file: 'file' in patch ? snapshotFile(patch.file) : existing.file,
73
+ error: 'error' in patch ? snapshotError(patch.error) : existing.error,
74
+ endedAt: 'endedAt' in patch ? (patch.endedAt ?? null) : existing.endedAt,
75
+ };
76
+ }
77
+ /** Validates `patch` against `existing` (status enum, then transition graph) and returns the next stored row. */
78
+ export function applyTaskPatch(existing, patch, now) {
79
+ const status = patch.status ?? existing.status;
80
+ assertValidStatus(status);
81
+ // CR-013: enum membership alone doesn't prove the transition is legal
82
+ // (e.g. `done` -> `running`) — check the actual lifecycle graph too.
83
+ if (!ALLOWED_TRANSITIONS[existing.status].has(status)) {
84
+ throw new RangeError(`Invalid media task transition: "${existing.status}" -> "${status}"`);
85
+ }
86
+ const payload = patchedPayload(existing, patch);
87
+ return {
88
+ id: existing.id,
89
+ ownerRef: existing.ownerRef,
90
+ status,
91
+ progress: payload.progress,
92
+ file: payload.file,
93
+ error: payload.error,
94
+ startedAt: existing.startedAt,
95
+ endedAt: payload.endedAt,
96
+ createdAt: existing.createdAt,
97
+ updatedAt: now,
98
+ ...patchedLabels(existing, patch),
99
+ };
100
+ }
101
+ export function assertValidTerminalTtl(terminalTtlMs) {
102
+ if (!Number.isFinite(terminalTtlMs) || terminalTtlMs < 0) {
103
+ throw new RangeError(`Invalid terminalTtlMs: ${terminalTtlMs} must be a non-negative finite number`);
104
+ }
105
+ }
106
+ /**
107
+ * A restart mid-flight has no way to resume a `queued`/`running` task, so it
108
+ * becomes `interrupted` (keeping an already-set `endedAt`); a terminal task
109
+ * whose `endedAt` (or, failing that, `updatedAt`) is older than `cutoff` is
110
+ * deleted. A task interrupted in this pass is never also deleted in it.
111
+ */
112
+ export function reconcileAction(task, now, cutoff) {
113
+ if (task.status === 'queued' || task.status === 'running') {
114
+ return {
115
+ kind: 'interrupt',
116
+ next: { ...task, status: 'interrupted', error: INTERRUPTED_ERROR, endedAt: task.endedAt ?? now, updatedAt: now },
117
+ };
118
+ }
119
+ if (TERMINAL_STATUSES.has(task.status) && (task.endedAt ?? task.updatedAt) < cutoff) {
120
+ return { kind: 'delete' };
121
+ }
122
+ return { kind: 'keep' };
123
+ }
124
+ //# sourceMappingURL=task-lifecycle.js.map
@@ -14,29 +14,7 @@
14
14
  * `@jini-ai/sqlite-chat` addition) implements the same interface — see
15
15
  * `archived provenance ledger`.
16
16
  */
17
- const VALID_STATUSES = new Set([
18
- 'queued',
19
- 'running',
20
- 'done',
21
- 'failed',
22
- 'interrupted',
23
- ]);
24
- const TERMINAL_STATUSES = new Set(['done', 'failed', 'interrupted']);
25
- // CR-013: `assertValidStatus` alone only proves enum membership, not that a
26
- // transition is legal — it allowed e.g. `done` -> `running`. This is the
27
- // actual lifecycle graph the store's own docs claim
28
- // (queued -> running -> done|failed|interrupted); same-state is included so
29
- // a caller can `update()` progress/file without also having to re-derive the
30
- // current status, but nothing can leave a terminal state once reached.
31
- const ALLOWED_TRANSITIONS = {
32
- // `queued` may go straight to a terminal state too (a caller isn't
33
- // required to make a separate "now running" update before finishing).
34
- queued: new Set(['queued', 'running', 'done', 'failed', 'interrupted']),
35
- running: new Set(['running', 'done', 'failed', 'interrupted']),
36
- done: new Set(['done']),
37
- failed: new Set(['failed']),
38
- interrupted: new Set(['interrupted']),
39
- };
17
+ import { applyTaskPatch, assertValidTerminalTtl, buildNewTask, reconcileAction, TERMINAL_STATUSES } from './task-lifecycle.js';
40
18
  function cloneTask(task) {
41
19
  return {
42
20
  ...task,
@@ -45,10 +23,6 @@ function cloneTask(task) {
45
23
  error: task.error == null ? null : { ...task.error },
46
24
  };
47
25
  }
48
- const INTERRUPTED_ERROR = {
49
- message: 'media task interrupted by daemon restart',
50
- code: 'DAEMON_RESTART',
51
- };
52
26
  /** Creates the in-memory reference `MediaTaskStore`. No persistence — state is lost on process exit. */
53
27
  export function createInMemoryMediaTaskStore() {
54
28
  const tasks = new Map();
@@ -57,24 +31,7 @@ export function createInMemoryMediaTaskStore() {
57
31
  if (tasks.has(input.id)) {
58
32
  throw new Error(`media task "${input.id}" already exists`);
59
33
  }
60
- const status = input.status ?? 'queued';
61
- assertValidStatus(status);
62
- const now = Date.now();
63
- const startedAt = input.startedAt ?? now;
64
- const task = {
65
- id: input.id,
66
- ownerRef: input.ownerRef,
67
- status,
68
- progress: input.progress ? [...input.progress] : [],
69
- file: input.file == null ? null : structuredClone(input.file),
70
- error: input.error == null ? null : { ...input.error },
71
- startedAt,
72
- endedAt: null,
73
- createdAt: now,
74
- updatedAt: now,
75
- ...(input.surface !== undefined ? { surface: input.surface } : {}),
76
- ...(input.model !== undefined ? { model: input.model } : {}),
77
- };
34
+ const task = buildNewTask(input, Date.now());
78
35
  tasks.set(task.id, task);
79
36
  return cloneTask(task);
80
37
  },
@@ -86,29 +43,7 @@ export function createInMemoryMediaTaskStore() {
86
43
  const existing = tasks.get(id);
87
44
  if (!existing)
88
45
  return null;
89
- const status = patch.status ?? existing.status;
90
- assertValidStatus(status);
91
- // CR-013: enum membership alone doesn't prove the transition is legal
92
- // (e.g. `done` -> `running`) — check the actual lifecycle graph too.
93
- if (!ALLOWED_TRANSITIONS[existing.status].has(status)) {
94
- throw new RangeError(`Invalid media task transition: "${existing.status}" -> "${status}"`);
95
- }
96
- const surface = 'surface' in patch ? (patch.surface ?? undefined) : existing.surface;
97
- const model = 'model' in patch ? (patch.model ?? undefined) : existing.model;
98
- const next = {
99
- id: existing.id,
100
- ownerRef: existing.ownerRef,
101
- status,
102
- progress: patch.progress ? [...patch.progress] : existing.progress,
103
- file: 'file' in patch ? (patch.file == null ? null : structuredClone(patch.file)) : existing.file,
104
- error: 'error' in patch ? (patch.error == null ? null : { ...patch.error }) : existing.error,
105
- startedAt: existing.startedAt,
106
- endedAt: 'endedAt' in patch ? (patch.endedAt ?? null) : existing.endedAt,
107
- createdAt: existing.createdAt,
108
- updatedAt: Date.now(),
109
- ...(surface !== undefined ? { surface } : {}),
110
- ...(model !== undefined ? { model } : {}),
111
- };
46
+ const next = applyTaskPatch(existing, patch, Date.now());
112
47
  tasks.set(id, next);
113
48
  return cloneTask(next);
114
49
  },
@@ -124,26 +59,18 @@ export function createInMemoryMediaTaskStore() {
124
59
  tasks.delete(id);
125
60
  },
126
61
  async reconcileOnBoot(options) {
127
- if (!Number.isFinite(options.terminalTtlMs) || options.terminalTtlMs < 0) {
128
- throw new RangeError(`Invalid terminalTtlMs: ${options.terminalTtlMs} must be a non-negative finite number`);
129
- }
62
+ assertValidTerminalTtl(options.terminalTtlMs);
130
63
  const now = options.now ?? Date.now();
131
64
  const cutoff = now - options.terminalTtlMs;
132
65
  let interrupted = 0;
133
66
  let deleted = 0;
134
67
  for (const task of [...tasks.values()]) {
135
- if (task.status === 'queued' || task.status === 'running') {
136
- tasks.set(task.id, {
137
- ...task,
138
- status: 'interrupted',
139
- error: INTERRUPTED_ERROR,
140
- endedAt: task.endedAt ?? now,
141
- updatedAt: now,
142
- });
68
+ const action = reconcileAction(task, now, cutoff);
69
+ if (action.kind === 'interrupt') {
70
+ tasks.set(task.id, action.next);
143
71
  interrupted += 1;
144
- continue;
145
72
  }
146
- if (TERMINAL_STATUSES.has(task.status) && (task.endedAt ?? task.updatedAt) < cutoff) {
73
+ else if (action.kind === 'delete') {
147
74
  tasks.delete(task.id);
148
75
  deleted += 1;
149
76
  }
@@ -152,9 +79,4 @@ export function createInMemoryMediaTaskStore() {
152
79
  },
153
80
  };
154
81
  }
155
- function assertValidStatus(status) {
156
- if (!VALID_STATUSES.has(status)) {
157
- throw new RangeError(`Invalid media task status: "${status}"`);
158
- }
159
- }
160
82
  //# sourceMappingURL=task-store.js.map
@@ -0,0 +1,10 @@
1
+ import type { MediaProviderOption, ProviderPreset } from '@jini-ai/core';
2
+ export declare const DEFAULT_MEDIA_PROVIDER_CATALOG: readonly MediaProviderOption[];
3
+ /**
4
+ * A small, vendor-shaped starting catalog. Deliberately NOT the origin's full
5
+ * ~30-entry list: that list is hand-curated product content that goes stale,
6
+ * and this package's rule for tables like this (see `LanguageTab`) is that the
7
+ * host owns them. Pass these explicitly as `presets` to the UI.
8
+ */
9
+ export declare const DEFAULT_PROVIDER_PRESETS: readonly ProviderPreset<'anthropic' | 'openai' | 'azure' | 'google'>[];
10
+ //# sourceMappingURL=ui-defaults.d.ts.map
@@ -0,0 +1,167 @@
1
+ import { canonicalMediaProviderId, findProvider, VENDOR_API_BASE_URLS } from './providers.js';
2
+ /**
3
+ * An explicit starter catalog for host composition. Sourced by driving the origin's
4
+ * Settings → Media providers
5
+ * panel directly (Playwright) and transcribing its real provider list, base URLs, and default
6
+ * models. Pass this explicitly as `catalog` to `MediaProvidersTab`; Zana or any
7
+ * other host is expected to do so once it has its own provider roster.
8
+ */
9
+ const starterCatalog = [
10
+ {
11
+ id: 'nano-banana',
12
+ label: 'Nano Banana',
13
+ models: ['gemini-3.1-flash-image-preview'],
14
+ },
15
+ {
16
+ id: 'aihubmix',
17
+ label: 'AIHubMix',
18
+ models: ['gemini-3.1-flash-image-preview'],
19
+ },
20
+ {
21
+ id: 'custom-image-api',
22
+ label: 'Custom Media API',
23
+ models: ['gemini-3.1-flash-image-preview'],
24
+ },
25
+ {
26
+ id: 'elevenlabs',
27
+ label: 'ElevenLabs',
28
+ },
29
+ {
30
+ id: 'fal-ai',
31
+ label: 'Fal.ai',
32
+ models: ['gemini-3.1-flash-image-preview'],
33
+ },
34
+ {
35
+ id: 'fishaudio',
36
+ label: 'FishAudio',
37
+ },
38
+ {
39
+ id: 'imagerouter',
40
+ label: 'ImageRouter',
41
+ models: ['gemini-3.1-flash-image-preview'],
42
+ },
43
+ {
44
+ id: 'leonardo-ai',
45
+ label: 'Leonardo.ai',
46
+ },
47
+ {
48
+ id: 'minimax',
49
+ label: 'MiniMax',
50
+ },
51
+ {
52
+ id: 'openai',
53
+ label: 'OpenAI',
54
+ models: ['gpt-image-2', 'dall-e-3'],
55
+ },
56
+ {
57
+ id: 'openrouter',
58
+ label: 'OpenRouter',
59
+ },
60
+ {
61
+ id: 'senseaudio',
62
+ label: 'SenseAudio',
63
+ },
64
+ {
65
+ id: 'tavily-search',
66
+ label: 'Tavily Search',
67
+ },
68
+ {
69
+ id: 'volcengine-ark',
70
+ label: 'Volcengine Ark (Doubao)',
71
+ },
72
+ {
73
+ id: 'xai-grok-imagine',
74
+ label: 'xAI Grok Imagine',
75
+ },
76
+ ];
77
+ export const DEFAULT_MEDIA_PROVIDER_CATALOG = starterCatalog.map((entry) => {
78
+ const id = canonicalMediaProviderId({ id: entry.id });
79
+ const provider = findProvider({ id });
80
+ return { ...entry, id, label: provider.label, ...(provider.defaultBaseUrl ? { defaultBaseUrl: provider.defaultBaseUrl } : {}) };
81
+ });
82
+ /**
83
+ * A small, vendor-shaped starting catalog. Deliberately NOT the origin's full
84
+ * ~30-entry list: that list is hand-curated product content that goes stale,
85
+ * and this package's rule for tables like this (see `LanguageTab`) is that the
86
+ * host owns them. Pass these explicitly as `presets` to the UI.
87
+ */
88
+ export const DEFAULT_PROVIDER_PRESETS = [
89
+ {
90
+ id: 'anthropic',
91
+ title: 'Anthropic',
92
+ protocol: 'anthropic',
93
+ baseUrl: VENDOR_API_BASE_URLS.anthropic,
94
+ preferredModels: ['claude-sonnet-5', 'claude-opus-5', 'claude-haiku-4-5'],
95
+ kind: 'protocol',
96
+ apiKeyPrefix: 'sk-ant-',
97
+ },
98
+ {
99
+ id: 'openai',
100
+ title: 'OpenAI',
101
+ protocol: 'openai',
102
+ baseUrl: VENDOR_API_BASE_URLS.openai,
103
+ // `gpt-4o`/`gpt-4o-mini`/`o3`/`o4-mini` are stale: OpenAI's GPT-5.6 family
104
+ // (released 2026-07-09, per the API changelog) replaced the old
105
+ // flagship/mini/nano naming with named tiers — sol/terra/luna. `sol` is
106
+ // the one the changelog and pricing docs call out as "recommended for
107
+ // production API usage", so it leads (see `preferredModels[0]` default
108
+ // in `rules.ts`) rather than the newer, pricier `gpt-6-astra` flagship
109
+ // (released 2026-09-03) — picking that as the silent default would jump
110
+ // an existing user's cost without them choosing it.
111
+ preferredModels: ['gpt-5.6-sol', 'gpt-5.6-terra', 'gpt-5.6-luna'],
112
+ kind: 'protocol',
113
+ apiKeyPrefix: 'sk-',
114
+ },
115
+ {
116
+ id: 'azure-openai',
117
+ title: 'Azure OpenAI',
118
+ protocol: 'azure',
119
+ baseUrl: VENDOR_API_BASE_URLS.azure,
120
+ preferredModels: [],
121
+ kind: 'protocol',
122
+ // No `apiKeyPrefix` deliberately: an Azure OpenAI key is a bare hex string with no vendor
123
+ // prefix, so any value here would be a guess — and a wrong prefix claim does not merely stay
124
+ // silent, it lets some OTHER vendor's valid key be announced as Azure's. Its 32 hex characters
125
+ // are also the shortest real key shape in this catalog, which is what sets
126
+ // `MIN_PLAUSIBLE_API_KEY_LENGTH`.
127
+ },
128
+ {
129
+ id: 'google-gemini',
130
+ title: 'Google Gemini',
131
+ protocol: 'google',
132
+ baseUrl: VENDOR_API_BASE_URLS.google,
133
+ // Ordered newest-first: `rules.ts`'s `saved?.model ?? preset.preferredModels[0]` makes entry [0]
134
+ // the default for anyone who has never picked a model, so a stale head silently pins new users
135
+ // to an old generation. Reported live: the field defaulted to `gemini-2.5-flash` while the
136
+ // operator was actually running `gemini-3.6-flash`. This list is only a FALLBACK — the form
137
+ // prefers live `listModels` discovery and drops back here when that call fails.
138
+ preferredModels: ['gemini-3.6-flash', 'gemini-2.5-flash', 'gemini-2.5-pro'],
139
+ kind: 'protocol',
140
+ // `AIza` + 35 characters is the classic Google key shape, and it is recorded here so a key of
141
+ // this shape is recognised as GOOGLE'S when it turns up in some other provider's field.
142
+ // Emphatically not a test that a Google key must look like this: an operator pasted a real,
143
+ // working Gemini key in a newer shape and the old allowlist told them it was not a Google key.
144
+ apiKeyPrefix: 'AIza',
145
+ },
146
+ {
147
+ id: 'openrouter',
148
+ title: 'OpenRouter',
149
+ protocol: 'openai',
150
+ baseUrl: VENDOR_API_BASE_URLS.openrouter,
151
+ preferredModels: ['anthropic/claude-sonnet-5', 'google/gemini-2.5-pro', 'openai/gpt-5.6-sol'],
152
+ kind: 'gateway',
153
+ // Longer than OpenAI's `sk-`, and deliberately so: `apiKeyFormatWarning` resolves a key to the
154
+ // MOST specific prefix that claims it, so `sk-or-v1-…` is attributed here rather than to OpenAI.
155
+ apiKeyPrefix: 'sk-or-',
156
+ },
157
+ {
158
+ id: 'ollama',
159
+ title: 'Ollama',
160
+ protocol: 'openai',
161
+ baseUrl: VENDOR_API_BASE_URLS.ollama,
162
+ preferredModels: [],
163
+ kind: 'gateway',
164
+ requiresApiKey: false,
165
+ },
166
+ ];
167
+ //# sourceMappingURL=ui-defaults.js.map