deepline 0.3.45 → 0.3.46
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/dist/bundling-sources/sdk/src/client.ts +2 -3
- package/dist/bundling-sources/sdk/src/errors.ts +2 -2
- package/dist/bundling-sources/sdk/src/http.ts +1 -1
- package/dist/bundling-sources/sdk/src/play.ts +7 -10
- package/dist/bundling-sources/sdk/src/plays/bundle-play-file.ts +3 -3
- package/dist/bundling-sources/sdk/src/release.ts +3 -3
- package/dist/bundling-sources/sdk/src/version.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-data-plane/contracts.ts +25 -0
- package/dist/bundling-sources/shared_libs/play-data-plane/index.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +19 -19
- package/dist/bundling-sources/shared_libs/play-runtime/backend.ts +5 -6
- package/dist/bundling-sources/shared_libs/play-runtime/cell-staleness.ts +1 -66
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +11 -11
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +3 -3
- package/dist/bundling-sources/shared_libs/play-runtime/dataset-id.ts +4 -3
- package/dist/bundling-sources/shared_libs/play-runtime/durable-call-cache.ts +3 -4
- package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/email-status.ts +1 -275
- package/dist/bundling-sources/shared_libs/play-runtime/execution-ledger-store.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/extractor-targets.ts +1 -106
- package/dist/bundling-sources/shared_libs/play-runtime/gateway-postgres-admission.ts +1 -2
- package/dist/bundling-sources/shared_libs/play-runtime/governor/in-memory-rate-state-backend.ts +13 -4
- package/dist/bundling-sources/shared_libs/play-runtime/live-events.ts +1 -5
- package/dist/bundling-sources/shared_libs/play-runtime/map-row-identity.ts +2 -3
- package/dist/bundling-sources/shared_libs/play-runtime/map-row-outcome.ts +2 -1
- package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/projection.ts +5 -5
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +3 -3
- package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +4 -4
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-modal-fallback.ts +3 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +8 -8
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +4 -4
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/local-process.ts +7 -7
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +7 -7
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/bundle.ts +13 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/index.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runner-events.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +6 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-constants.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-constraints.ts +1 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-env.ts +55 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runtime-limits.ts +1 -109
- package/dist/bundling-sources/shared_libs/play-runtime/step-program-dataset-builder.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execution-outcome.ts +6 -5
- package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result-types.ts +1 -206
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +10 -7
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +1 -1
- package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +8 -3
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +4 -4
- package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +3 -6
- package/dist/bundling-sources/shared_libs/plays/cell-staleness.ts +66 -0
- package/dist/bundling-sources/shared_libs/plays/compiler-manifest.ts +1 -1
- package/dist/bundling-sources/shared_libs/plays/contracts.ts +2 -2
- package/dist/bundling-sources/shared_libs/plays/core.ts +466 -0
- package/dist/bundling-sources/shared_libs/plays/email-status.ts +287 -0
- package/dist/bundling-sources/shared_libs/plays/extractor-targets.ts +106 -0
- package/dist/bundling-sources/shared_libs/plays/row-identity.ts +1 -3
- package/dist/bundling-sources/shared_libs/plays/runtime-constraints.ts +2 -0
- package/dist/bundling-sources/shared_libs/plays/runtime-validation.ts +4 -2
- package/dist/bundling-sources/shared_libs/plays/sandbox-runtime-limits.ts +109 -0
- package/dist/bundling-sources/shared_libs/plays/tool-execution-error.ts +624 -0
- package/dist/bundling-sources/shared_libs/plays/tool-result-types.ts +206 -0
- package/dist/bundling-sources/shared_libs/security/safe-outbound-fetch.ts +1 -1
- package/dist/cli/index.js +174 -168
- package/dist/cli/index.mjs +182 -169
- package/dist/{compiler-manifest-DwYe2C2S.d.mts → compiler-manifest-BuoqasqI.d.mts} +585 -540
- package/dist/{compiler-manifest-DwYe2C2S.d.ts → compiler-manifest-BuoqasqI.d.ts} +585 -540
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +47 -40
- package/dist/index.mjs +47 -40
- package/dist/install-integrity.json +13 -3
- package/dist/plays/bundle-play-file.d.mts +4 -61
- package/dist/plays/bundle-play-file.d.ts +4 -61
- package/dist/plays/bundle-play-file.mjs +157 -155
- package/package.json +9 -6
- /package/dist/bundling-sources/shared_libs/{play-runtime → plays}/tool-response-contract.ts +0 -0
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import type { PlayDataset, PlayDatasetInput } from './dataset.js';
|
|
2
|
+
import type { ToolExecuteResult } from './tool-result-types';
|
|
3
|
+
import type {
|
|
4
|
+
DurableCallStaleAfterSeconds,
|
|
5
|
+
PlayAuthoringBindings,
|
|
6
|
+
PlayAuthoringColumnResolver,
|
|
7
|
+
PlayAuthoringConditionalStepResolver,
|
|
8
|
+
PlayAuthoringDatasetBuilder,
|
|
9
|
+
PlayAuthoringDatasetDefinitionOptions,
|
|
10
|
+
PlayAuthoringDatasetRowKey,
|
|
11
|
+
PlayAuthoringDatasetRunOptions,
|
|
12
|
+
PlayAuthoringDefineConfig,
|
|
13
|
+
PlayAuthoringDefinedPlay,
|
|
14
|
+
PlayAuthoringInputContract,
|
|
15
|
+
PlayAuthoringReferenceLike,
|
|
16
|
+
PlayAuthoringRuntimeContext,
|
|
17
|
+
PlayAuthoringStepOptions,
|
|
18
|
+
PlayAuthoringStepProgram,
|
|
19
|
+
PlayAuthoringStepProgramOutput,
|
|
20
|
+
PlayAuthoringStepProgramResolver,
|
|
21
|
+
PlayAuthoringStepProgramStep,
|
|
22
|
+
PlayAuthoringStepResolver,
|
|
23
|
+
PlayLooseObject,
|
|
24
|
+
PlayReturnObject as PlayAuthoringReturnObject,
|
|
25
|
+
PlaySecretAuth,
|
|
26
|
+
PlaySecretAuthInput,
|
|
27
|
+
PlaySecretAwareRequestInit,
|
|
28
|
+
PlaySecretHandle,
|
|
29
|
+
PlaySecretPromise,
|
|
30
|
+
PlaySecretValue,
|
|
31
|
+
PlaySqlQuery,
|
|
32
|
+
PlaySqlListenerDeclaration,
|
|
33
|
+
PlaySqlListenerEvent,
|
|
34
|
+
PlaySqlListenerFilterOperator,
|
|
35
|
+
PlaySqlListenerFilterScalar,
|
|
36
|
+
PlaySqlListenerOperation,
|
|
37
|
+
PlaySqlListenerWhere,
|
|
38
|
+
PlayToolExecutionRequest,
|
|
39
|
+
} from './authoring-contract';
|
|
40
|
+
import { createPlayInputContract } from './input-contract-definition';
|
|
41
|
+
|
|
42
|
+
export type { ToolExecuteResult } from './tool-result-types';
|
|
43
|
+
|
|
44
|
+
export type PlayBindings = PlayAuthoringBindings;
|
|
45
|
+
export type SqlListenerOperation = PlaySqlListenerOperation;
|
|
46
|
+
export type SqlListenerFilterScalar = PlaySqlListenerFilterScalar;
|
|
47
|
+
export type SqlListenerFilterOperator = PlaySqlListenerFilterOperator;
|
|
48
|
+
export type SqlListenerWhere = PlaySqlListenerWhere;
|
|
49
|
+
export type SqlListenerDeclaration = PlaySqlListenerDeclaration;
|
|
50
|
+
|
|
51
|
+
export type SqlListenerEvent<T extends object = Record<string, unknown>> =
|
|
52
|
+
PlaySqlListenerEvent<T>;
|
|
53
|
+
|
|
54
|
+
/** @deprecated Pass a SQL string directly to ctx.customerDb.query. */
|
|
55
|
+
export type SqlQuery = PlaySqlQuery;
|
|
56
|
+
export type SecretHandle = PlaySecretHandle;
|
|
57
|
+
export type SecretPromise = PlaySecretPromise;
|
|
58
|
+
export type SecretValue = PlaySecretValue;
|
|
59
|
+
export type SecretAuth = PlaySecretAuth;
|
|
60
|
+
export type SecretAuthInput = PlaySecretAuthInput;
|
|
61
|
+
export type SecretAwareRequestInit = PlaySecretAwareRequestInit;
|
|
62
|
+
export type LoosePlayObject = PlayLooseObject;
|
|
63
|
+
|
|
64
|
+
export type ToolExecutionRequest = PlayToolExecutionRequest;
|
|
65
|
+
|
|
66
|
+
export type StepResolver<Row, Value> = PlayAuthoringStepResolver<
|
|
67
|
+
Row,
|
|
68
|
+
Value,
|
|
69
|
+
DeeplinePlayRuntimeContext
|
|
70
|
+
>;
|
|
71
|
+
|
|
72
|
+
export type ConditionalStepResolver<
|
|
73
|
+
Row,
|
|
74
|
+
Value,
|
|
75
|
+
Else = null,
|
|
76
|
+
> = PlayAuthoringConditionalStepResolver<
|
|
77
|
+
Row,
|
|
78
|
+
Value,
|
|
79
|
+
DeeplinePlayRuntimeContext,
|
|
80
|
+
Else
|
|
81
|
+
>;
|
|
82
|
+
|
|
83
|
+
export type StepOptions<Row, Value = unknown> = PlayAuthoringStepOptions<
|
|
84
|
+
Row,
|
|
85
|
+
Value
|
|
86
|
+
>;
|
|
87
|
+
|
|
88
|
+
export type StepProgram<
|
|
89
|
+
Input,
|
|
90
|
+
Output,
|
|
91
|
+
Return = Output,
|
|
92
|
+
> = PlayAuthoringStepProgram<Input, Output, DeeplinePlayRuntimeContext, Return>;
|
|
93
|
+
|
|
94
|
+
export type StepProgramResolver<Input, Return> =
|
|
95
|
+
PlayAuthoringStepProgramResolver<Input, Return, DeeplinePlayRuntimeContext>;
|
|
96
|
+
|
|
97
|
+
export type PlayStepProgramStep =
|
|
98
|
+
PlayAuthoringStepProgramStep<DeeplinePlayRuntimeContext>;
|
|
99
|
+
|
|
100
|
+
export type ColumnResolver<Row, Value> = PlayAuthoringColumnResolver<
|
|
101
|
+
Row,
|
|
102
|
+
Value,
|
|
103
|
+
DeeplinePlayRuntimeContext
|
|
104
|
+
>;
|
|
105
|
+
|
|
106
|
+
export type StepProgramOutput<TProgram> =
|
|
107
|
+
PlayAuthoringStepProgramOutput<TProgram>;
|
|
108
|
+
|
|
109
|
+
export type DatasetRowKey<InputRow extends object> =
|
|
110
|
+
PlayAuthoringDatasetRowKey<InputRow>;
|
|
111
|
+
|
|
112
|
+
export type DatasetDefinitionOptions<InputRow extends object> =
|
|
113
|
+
PlayAuthoringDatasetDefinitionOptions<InputRow>;
|
|
114
|
+
|
|
115
|
+
export type DatasetRunOptions<InputRow extends object> =
|
|
116
|
+
PlayAuthoringDatasetRunOptions<InputRow>;
|
|
117
|
+
|
|
118
|
+
export type DatasetBuilder<
|
|
119
|
+
InputRow extends object,
|
|
120
|
+
OutputRow extends object,
|
|
121
|
+
> = PlayAuthoringDatasetBuilder<
|
|
122
|
+
InputRow,
|
|
123
|
+
OutputRow,
|
|
124
|
+
DeeplinePlayRuntimeContext
|
|
125
|
+
>;
|
|
126
|
+
|
|
127
|
+
export type PlayReferenceLike = PlayAuthoringReferenceLike;
|
|
128
|
+
|
|
129
|
+
export type DeeplinePlayRuntimeContext = PlayAuthoringRuntimeContext;
|
|
130
|
+
|
|
131
|
+
export type PlayReturnObject = PlayAuthoringReturnObject;
|
|
132
|
+
export type PlayInputContract<TInput> = PlayAuthoringInputContract<TInput>;
|
|
133
|
+
export type DefinePlayConfig<
|
|
134
|
+
TInput,
|
|
135
|
+
TOutput extends PlayReturnObject,
|
|
136
|
+
> = PlayAuthoringDefineConfig<TInput, TOutput, DeeplinePlayRuntimeContext>;
|
|
137
|
+
|
|
138
|
+
export type PlayMetadata = {
|
|
139
|
+
name: string;
|
|
140
|
+
description?: string;
|
|
141
|
+
bindings?: PlayBindings;
|
|
142
|
+
inputSchema?: Record<string, unknown>;
|
|
143
|
+
billing?: PlayBindings['billing'];
|
|
144
|
+
runtime?: PlayBindings['runtime'];
|
|
145
|
+
compatibility?: PlayBindings['compatibility'];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export type CoreNamedPlayHandle<
|
|
149
|
+
TInput = Record<string, unknown>,
|
|
150
|
+
TOutput = unknown,
|
|
151
|
+
> = {
|
|
152
|
+
readonly name: string;
|
|
153
|
+
get(): Promise<unknown>;
|
|
154
|
+
runs(): Promise<unknown>;
|
|
155
|
+
versions(): Promise<unknown>;
|
|
156
|
+
publish(options?: { revisionId?: string }): Promise<unknown>;
|
|
157
|
+
clearHistory(options?: { tableNamespaces?: string[] }): Promise<unknown>;
|
|
158
|
+
run(input: TInput, options?: { revisionId?: string }): Promise<unknown>;
|
|
159
|
+
runSync(input: TInput, options?: { revisionId?: string }): Promise<TOutput>;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export type DefinedPlay<
|
|
163
|
+
TInput,
|
|
164
|
+
TOutput extends PlayReturnObject,
|
|
165
|
+
THandle extends object = CoreNamedPlayHandle<TInput, TOutput>,
|
|
166
|
+
> = PlayAuthoringDefinedPlay<
|
|
167
|
+
TInput,
|
|
168
|
+
TOutput,
|
|
169
|
+
DeeplinePlayRuntimeContext,
|
|
170
|
+
THandle
|
|
171
|
+
>;
|
|
172
|
+
|
|
173
|
+
export const PLAY_METADATA_SYMBOL = Symbol.for('deepline.play.metadata');
|
|
174
|
+
|
|
175
|
+
class PlayCoreConditionalStepResolver<
|
|
176
|
+
Row,
|
|
177
|
+
Value,
|
|
178
|
+
ElseValue,
|
|
179
|
+
> implements ConditionalStepResolver<Row, Value, ElseValue> {
|
|
180
|
+
readonly kind = 'conditional' as const;
|
|
181
|
+
|
|
182
|
+
constructor(
|
|
183
|
+
readonly when: (row: Row, index: number) => boolean | Promise<boolean>,
|
|
184
|
+
readonly run: StepResolver<Row, Value>,
|
|
185
|
+
readonly elseValue: ElseValue,
|
|
186
|
+
) {}
|
|
187
|
+
|
|
188
|
+
else<ValueElse>(
|
|
189
|
+
value: ValueElse,
|
|
190
|
+
): ConditionalStepResolver<Row, Value, ValueElse> {
|
|
191
|
+
return new PlayCoreConditionalStepResolver(this.when, this.run, value);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
class PlayCoreStepProgram<Input, Output, ReturnValue> implements StepProgram<
|
|
196
|
+
Input,
|
|
197
|
+
Output,
|
|
198
|
+
ReturnValue
|
|
199
|
+
> {
|
|
200
|
+
readonly kind = 'steps' as const;
|
|
201
|
+
declare readonly __inputType?: (input: Input) => void;
|
|
202
|
+
|
|
203
|
+
constructor(
|
|
204
|
+
readonly steps: readonly PlayStepProgramStep[],
|
|
205
|
+
readonly returnResolver?: StepResolver<Output, ReturnValue>,
|
|
206
|
+
) {}
|
|
207
|
+
|
|
208
|
+
step<Name extends string, Value>(
|
|
209
|
+
name: Name,
|
|
210
|
+
resolver:
|
|
211
|
+
| StepResolver<Output, Value>
|
|
212
|
+
| ConditionalStepResolver<Output, Value>
|
|
213
|
+
| StepProgramResolver<Output, Value>,
|
|
214
|
+
): StepProgram<Input, Output & Record<Name, Value>, ReturnValue>;
|
|
215
|
+
step<Name extends string, Value>(
|
|
216
|
+
name: Name,
|
|
217
|
+
resolver: StepResolver<Output, Value> | StepProgramResolver<Output, Value>,
|
|
218
|
+
options: StepOptions<Output>,
|
|
219
|
+
): StepProgram<Input, Output & Record<Name, Value | null>, ReturnValue>;
|
|
220
|
+
step<Name extends string, Value>(
|
|
221
|
+
name: Name,
|
|
222
|
+
resolver:
|
|
223
|
+
| StepResolver<Output, Value>
|
|
224
|
+
| ConditionalStepResolver<Output, Value>
|
|
225
|
+
| StepProgramResolver<Output, Value>,
|
|
226
|
+
options?: StepOptions<Output>,
|
|
227
|
+
): StepProgram<Input, Output & Record<Name, Value | null>, ReturnValue> {
|
|
228
|
+
if (!name.trim()) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
'steps().step(name, ...) requires a non-empty step name.',
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const stepResolver =
|
|
234
|
+
options?.runIf && !isConditionalStepResolver(resolver)
|
|
235
|
+
? new PlayCoreConditionalStepResolver(
|
|
236
|
+
options.runIf,
|
|
237
|
+
resolver as StepResolver<Output, Value>,
|
|
238
|
+
null,
|
|
239
|
+
)
|
|
240
|
+
: resolver;
|
|
241
|
+
return new PlayCoreStepProgram(
|
|
242
|
+
[
|
|
243
|
+
...this.steps,
|
|
244
|
+
{
|
|
245
|
+
name,
|
|
246
|
+
...(options?.recompute === true ? { recompute: true } : {}),
|
|
247
|
+
...(options?.recomputeOnError === true
|
|
248
|
+
? { recomputeOnError: true }
|
|
249
|
+
: {}),
|
|
250
|
+
...(typeof options?.staleAfterSeconds === 'number'
|
|
251
|
+
? { staleAfterSeconds: options.staleAfterSeconds }
|
|
252
|
+
: {}),
|
|
253
|
+
resolver: stepResolver as PlayStepProgramStep['resolver'],
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
this.returnResolver as StepResolver<
|
|
257
|
+
Output & Record<Name, Value | null>,
|
|
258
|
+
ReturnValue
|
|
259
|
+
>,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return<Value>(
|
|
264
|
+
resolver: StepResolver<Output, Value>,
|
|
265
|
+
): StepProgram<Input, Output, Value> {
|
|
266
|
+
return new PlayCoreStepProgram(this.steps, resolver);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function isConditionalStepResolver(
|
|
271
|
+
value: unknown,
|
|
272
|
+
): value is ConditionalStepResolver<unknown, unknown> {
|
|
273
|
+
return (
|
|
274
|
+
value !== null &&
|
|
275
|
+
typeof value === 'object' &&
|
|
276
|
+
(value as { kind?: unknown }).kind === 'conditional'
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function steps<TInput>(): StepProgram<TInput, TInput, TInput> {
|
|
281
|
+
return new PlayCoreStepProgram<TInput, TInput, TInput>([]);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function defineInput<TInput>(
|
|
285
|
+
schema: Record<string, unknown>,
|
|
286
|
+
): PlayInputContract<TInput> {
|
|
287
|
+
return createPlayInputContract<TInput>(schema);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function createUnavailableNamedPlayHandle<
|
|
291
|
+
TInput,
|
|
292
|
+
TOutput extends PlayReturnObject,
|
|
293
|
+
>(name: string): CoreNamedPlayHandle<TInput, TOutput> {
|
|
294
|
+
const unavailable = () => {
|
|
295
|
+
throw new Error(
|
|
296
|
+
`definePlay("${name}") remote lifecycle methods are unavailable inside play execution. Use ctx.runPlay(...) for runtime composition.`,
|
|
297
|
+
);
|
|
298
|
+
};
|
|
299
|
+
return {
|
|
300
|
+
name,
|
|
301
|
+
get: unavailable,
|
|
302
|
+
runs: unavailable,
|
|
303
|
+
versions: unavailable,
|
|
304
|
+
publish: unavailable,
|
|
305
|
+
clearHistory: unavailable,
|
|
306
|
+
run: unavailable,
|
|
307
|
+
runSync: unavailable,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function createDefinedPlay<
|
|
312
|
+
TInput,
|
|
313
|
+
TOutput extends PlayReturnObject,
|
|
314
|
+
THandle extends object,
|
|
315
|
+
>(
|
|
316
|
+
nameOrConfig: string | DefinePlayConfig<TInput, TOutput>,
|
|
317
|
+
maybeFn:
|
|
318
|
+
| ((ctx: DeeplinePlayRuntimeContext, input: TInput) => Promise<TOutput>)
|
|
319
|
+
| undefined,
|
|
320
|
+
maybeBindings: PlayBindings | undefined,
|
|
321
|
+
createHandle: (name: string) => THandle,
|
|
322
|
+
): DefinedPlay<TInput, TOutput, THandle> {
|
|
323
|
+
const config =
|
|
324
|
+
typeof nameOrConfig === 'string'
|
|
325
|
+
? {
|
|
326
|
+
name: nameOrConfig,
|
|
327
|
+
fn: maybeFn,
|
|
328
|
+
bindings: maybeBindings,
|
|
329
|
+
description: maybeBindings?.description,
|
|
330
|
+
inputSchema: undefined,
|
|
331
|
+
billing: maybeBindings?.billing,
|
|
332
|
+
runtime: maybeBindings?.runtime,
|
|
333
|
+
compatibility: maybeBindings?.compatibility,
|
|
334
|
+
}
|
|
335
|
+
: {
|
|
336
|
+
name: nameOrConfig.id,
|
|
337
|
+
fn: nameOrConfig.run,
|
|
338
|
+
bindings: nameOrConfig.bindings,
|
|
339
|
+
description: nameOrConfig.description,
|
|
340
|
+
inputSchema: nameOrConfig.input.schema,
|
|
341
|
+
billing: nameOrConfig.billing,
|
|
342
|
+
runtime: nameOrConfig.runtime ?? nameOrConfig.bindings?.runtime,
|
|
343
|
+
compatibility:
|
|
344
|
+
nameOrConfig.compatibility ?? nameOrConfig.bindings?.compatibility,
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const name = config.name;
|
|
348
|
+
const fn = config.fn;
|
|
349
|
+
const description = config.description?.trim();
|
|
350
|
+
if (typeof fn !== 'function') {
|
|
351
|
+
throw new Error('definePlay(...) requires an async run function.');
|
|
352
|
+
}
|
|
353
|
+
if (name.includes('/')) {
|
|
354
|
+
throw new Error('Play name cannot contain "/". Slash is reserved.');
|
|
355
|
+
}
|
|
356
|
+
const normalizedName = name
|
|
357
|
+
.trim()
|
|
358
|
+
.replace(/[^a-z0-9]+/gi, '_')
|
|
359
|
+
.replace(/_+/g, '_')
|
|
360
|
+
.replace(/^_+|_+$/g, '')
|
|
361
|
+
.toLowerCase();
|
|
362
|
+
if (!normalizedName) {
|
|
363
|
+
throw new Error('Play name must contain a letter or number.');
|
|
364
|
+
}
|
|
365
|
+
if (normalizedName.length > 63) {
|
|
366
|
+
throw new Error(
|
|
367
|
+
`Play name too long after normalization (${normalizedName.length}/63): "${normalizedName}".`,
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const metadata: PlayMetadata = {
|
|
372
|
+
name,
|
|
373
|
+
...(description ? { description } : {}),
|
|
374
|
+
...(config.bindings ? { bindings: config.bindings } : {}),
|
|
375
|
+
...(config.inputSchema ? { inputSchema: config.inputSchema } : {}),
|
|
376
|
+
...(config.billing ? { billing: config.billing } : {}),
|
|
377
|
+
...(config.runtime ? { runtime: config.runtime } : {}),
|
|
378
|
+
...(config.compatibility ? { compatibility: config.compatibility } : {}),
|
|
379
|
+
};
|
|
380
|
+
const play = fn as DefinedPlay<TInput, TOutput, THandle>;
|
|
381
|
+
|
|
382
|
+
Object.defineProperty(play, PLAY_METADATA_SYMBOL, {
|
|
383
|
+
value: metadata,
|
|
384
|
+
enumerable: false,
|
|
385
|
+
configurable: false,
|
|
386
|
+
writable: false,
|
|
387
|
+
});
|
|
388
|
+
Object.defineProperty(play, 'playName', {
|
|
389
|
+
value: name,
|
|
390
|
+
enumerable: true,
|
|
391
|
+
configurable: false,
|
|
392
|
+
writable: false,
|
|
393
|
+
});
|
|
394
|
+
Object.defineProperty(play, 'bindings', {
|
|
395
|
+
value: config.bindings,
|
|
396
|
+
enumerable: true,
|
|
397
|
+
configurable: false,
|
|
398
|
+
writable: false,
|
|
399
|
+
});
|
|
400
|
+
Object.defineProperty(play, 'runtime', {
|
|
401
|
+
value: config.runtime,
|
|
402
|
+
enumerable: true,
|
|
403
|
+
configurable: false,
|
|
404
|
+
writable: false,
|
|
405
|
+
});
|
|
406
|
+
Object.defineProperty(play, 'compatibility', {
|
|
407
|
+
value: config.compatibility,
|
|
408
|
+
enumerable: true,
|
|
409
|
+
configurable: false,
|
|
410
|
+
writable: false,
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const handle = createHandle(name) as Record<PropertyKey, unknown>;
|
|
414
|
+
for (const key of Reflect.ownKeys(handle)) {
|
|
415
|
+
Object.defineProperty(play, key, {
|
|
416
|
+
value: handle[key],
|
|
417
|
+
enumerable: false,
|
|
418
|
+
configurable: false,
|
|
419
|
+
writable: false,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return play;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export function definePlay<TInput, TOutput extends PlayReturnObject>(
|
|
427
|
+
config: DefinePlayConfig<TInput, TOutput>,
|
|
428
|
+
): DefinedPlay<TInput, TOutput>;
|
|
429
|
+
export function definePlay<TInput, TOutput extends PlayReturnObject>(
|
|
430
|
+
name: string,
|
|
431
|
+
fn: (ctx: DeeplinePlayRuntimeContext, input: TInput) => Promise<TOutput>,
|
|
432
|
+
bindings?: PlayBindings,
|
|
433
|
+
): DefinedPlay<TInput, TOutput>;
|
|
434
|
+
export function definePlay<TInput, TOutput extends PlayReturnObject>(
|
|
435
|
+
nameOrConfig: string | DefinePlayConfig<TInput, TOutput>,
|
|
436
|
+
maybeFn?: (
|
|
437
|
+
ctx: DeeplinePlayRuntimeContext,
|
|
438
|
+
input: TInput,
|
|
439
|
+
) => Promise<TOutput>,
|
|
440
|
+
maybeBindings?: PlayBindings,
|
|
441
|
+
): DefinedPlay<TInput, TOutput> {
|
|
442
|
+
return createDefinedPlay(nameOrConfig, maybeFn, maybeBindings, (name) =>
|
|
443
|
+
createUnavailableNamedPlayHandle<TInput, TOutput>(name),
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export const defineWorkflow = definePlay;
|
|
448
|
+
|
|
449
|
+
export function getDefinedPlayMetadata(value: unknown): PlayMetadata | null {
|
|
450
|
+
if (typeof value !== 'function') {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
const metadata = (value as unknown as Record<PropertyKey, unknown>)[
|
|
454
|
+
PLAY_METADATA_SYMBOL
|
|
455
|
+
];
|
|
456
|
+
if (!metadata || typeof metadata !== 'object') {
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
const candidate = metadata as PlayMetadata;
|
|
460
|
+
if (!candidate.name || typeof candidate.name !== 'string') {
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
return candidate;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export type { PlayDataset, PlayDatasetInput };
|