@dxos/functions 0.8.3 → 0.8.4-main.03d5cd7b56

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 (142) hide show
  1. package/README.md +4 -6
  2. package/dist/lib/neutral/index.mjs +593 -0
  3. package/dist/lib/neutral/index.mjs.map +7 -0
  4. package/dist/lib/neutral/meta.json +1 -0
  5. package/dist/types/src/index.d.ts +3 -6
  6. package/dist/types/src/index.d.ts.map +1 -1
  7. package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
  8. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
  9. package/dist/types/src/protocol/functions-ai-http-client.test.d.ts +2 -0
  10. package/dist/types/src/protocol/functions-ai-http-client.test.d.ts.map +1 -0
  11. package/dist/types/src/protocol/index.d.ts +2 -0
  12. package/dist/types/src/protocol/index.d.ts.map +1 -0
  13. package/dist/types/src/protocol/protocol.d.ts +19 -0
  14. package/dist/types/src/protocol/protocol.d.ts.map +1 -0
  15. package/dist/types/src/protocol/protocol.test.d.ts +2 -0
  16. package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
  17. package/dist/types/src/sdk.d.ts +10 -0
  18. package/dist/types/src/sdk.d.ts.map +1 -0
  19. package/dist/types/src/services/credentials.d.ts +24 -27
  20. package/dist/types/src/services/credentials.d.ts.map +1 -1
  21. package/dist/types/src/services/function-invocation-service.d.ts +15 -0
  22. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
  23. package/dist/types/src/services/index.d.ts +3 -7
  24. package/dist/types/src/services/index.d.ts.map +1 -1
  25. package/dist/types/src/services/queues.d.ts +1 -17
  26. package/dist/types/src/services/queues.d.ts.map +1 -1
  27. package/dist/types/src/services/tracing.d.ts +4 -14
  28. package/dist/types/src/services/tracing.d.ts.map +1 -1
  29. package/dist/types/src/types/index.d.ts +2 -0
  30. package/dist/types/src/types/index.d.ts.map +1 -0
  31. package/dist/types/src/types/url.d.ts +13 -0
  32. package/dist/types/src/types/url.d.ts.map +1 -0
  33. package/dist/types/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +28 -65
  35. package/src/index.ts +3 -8
  36. package/src/protocol/functions-ai-http-client.test.ts +105 -0
  37. package/src/protocol/functions-ai-http-client.ts +141 -0
  38. package/src/{executor → protocol}/index.ts +1 -1
  39. package/src/protocol/protocol.test.ts +58 -0
  40. package/src/protocol/protocol.ts +428 -0
  41. package/src/sdk.ts +31 -0
  42. package/src/services/credentials.ts +96 -35
  43. package/src/services/function-invocation-service.ts +33 -0
  44. package/src/services/index.ts +3 -7
  45. package/src/services/queues.ts +1 -33
  46. package/src/services/tracing.ts +4 -23
  47. package/src/{testing → types}/index.ts +1 -1
  48. package/src/types/url.ts +32 -0
  49. package/dist/lib/browser/bundler/index.mjs +0 -236
  50. package/dist/lib/browser/bundler/index.mjs.map +0 -7
  51. package/dist/lib/browser/chunk-WEFZUEL2.mjs +0 -300
  52. package/dist/lib/browser/chunk-WEFZUEL2.mjs.map +0 -7
  53. package/dist/lib/browser/edge/index.mjs +0 -69
  54. package/dist/lib/browser/edge/index.mjs.map +0 -7
  55. package/dist/lib/browser/index.mjs +0 -486
  56. package/dist/lib/browser/index.mjs.map +0 -7
  57. package/dist/lib/browser/meta.json +0 -1
  58. package/dist/lib/browser/testing/index.mjs +0 -28
  59. package/dist/lib/browser/testing/index.mjs.map +0 -7
  60. package/dist/lib/node/bundler/index.cjs +0 -260
  61. package/dist/lib/node/bundler/index.cjs.map +0 -7
  62. package/dist/lib/node/chunk-IJAE7FZK.cjs +0 -320
  63. package/dist/lib/node/chunk-IJAE7FZK.cjs.map +0 -7
  64. package/dist/lib/node/edge/index.cjs +0 -94
  65. package/dist/lib/node/edge/index.cjs.map +0 -7
  66. package/dist/lib/node/index.cjs +0 -522
  67. package/dist/lib/node/index.cjs.map +0 -7
  68. package/dist/lib/node/meta.json +0 -1
  69. package/dist/lib/node/testing/index.cjs +0 -43
  70. package/dist/lib/node/testing/index.cjs.map +0 -7
  71. package/dist/lib/node-esm/bundler/index.mjs +0 -238
  72. package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
  73. package/dist/lib/node-esm/chunk-LIYPMWNQ.mjs +0 -302
  74. package/dist/lib/node-esm/chunk-LIYPMWNQ.mjs.map +0 -7
  75. package/dist/lib/node-esm/edge/index.mjs +0 -71
  76. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  77. package/dist/lib/node-esm/index.mjs +0 -487
  78. package/dist/lib/node-esm/index.mjs.map +0 -7
  79. package/dist/lib/node-esm/meta.json +0 -1
  80. package/dist/lib/node-esm/testing/index.mjs +0 -29
  81. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  82. package/dist/types/src/bundler/bundler.d.ts +0 -51
  83. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  84. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  85. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  86. package/dist/types/src/bundler/index.d.ts +0 -2
  87. package/dist/types/src/bundler/index.d.ts.map +0 -1
  88. package/dist/types/src/edge/functions.d.ts +0 -16
  89. package/dist/types/src/edge/functions.d.ts.map +0 -1
  90. package/dist/types/src/edge/index.d.ts +0 -2
  91. package/dist/types/src/edge/index.d.ts.map +0 -1
  92. package/dist/types/src/executor/executor.d.ts +0 -8
  93. package/dist/types/src/executor/executor.d.ts.map +0 -1
  94. package/dist/types/src/executor/index.d.ts +0 -2
  95. package/dist/types/src/executor/index.d.ts.map +0 -1
  96. package/dist/types/src/handler.d.ts +0 -64
  97. package/dist/types/src/handler.d.ts.map +0 -1
  98. package/dist/types/src/schema.d.ts +0 -38
  99. package/dist/types/src/schema.d.ts.map +0 -1
  100. package/dist/types/src/services/ai.d.ts +0 -12
  101. package/dist/types/src/services/ai.d.ts.map +0 -1
  102. package/dist/types/src/services/database.d.ts +0 -11
  103. package/dist/types/src/services/database.d.ts.map +0 -1
  104. package/dist/types/src/services/event-logger.d.ts +0 -37
  105. package/dist/types/src/services/event-logger.d.ts.map +0 -1
  106. package/dist/types/src/services/function-call-service.d.ts +0 -16
  107. package/dist/types/src/services/function-call-service.d.ts.map +0 -1
  108. package/dist/types/src/services/service-container.d.ts +0 -44
  109. package/dist/types/src/services/service-container.d.ts.map +0 -1
  110. package/dist/types/src/testing/index.d.ts +0 -2
  111. package/dist/types/src/testing/index.d.ts.map +0 -1
  112. package/dist/types/src/testing/logger.d.ts +0 -5
  113. package/dist/types/src/testing/logger.d.ts.map +0 -1
  114. package/dist/types/src/testing/services.d.ts +0 -13
  115. package/dist/types/src/testing/services.d.ts.map +0 -1
  116. package/dist/types/src/trace.d.ts +0 -124
  117. package/dist/types/src/trace.d.ts.map +0 -1
  118. package/dist/types/src/translations.d.ts +0 -12
  119. package/dist/types/src/translations.d.ts.map +0 -1
  120. package/dist/types/src/types.d.ts +0 -411
  121. package/dist/types/src/types.d.ts.map +0 -1
  122. package/dist/types/src/url.d.ts +0 -17
  123. package/dist/types/src/url.d.ts.map +0 -1
  124. package/src/bundler/bundler.test.ts +0 -59
  125. package/src/bundler/bundler.ts +0 -270
  126. package/src/bundler/index.ts +0 -5
  127. package/src/edge/functions.ts +0 -64
  128. package/src/edge/index.ts +0 -9
  129. package/src/executor/executor.ts +0 -47
  130. package/src/handler.ts +0 -113
  131. package/src/schema.ts +0 -57
  132. package/src/services/ai.ts +0 -32
  133. package/src/services/database.ts +0 -28
  134. package/src/services/event-logger.ts +0 -87
  135. package/src/services/function-call-service.ts +0 -64
  136. package/src/services/service-container.ts +0 -109
  137. package/src/testing/logger.ts +0 -16
  138. package/src/testing/services.ts +0 -32
  139. package/src/trace.ts +0 -180
  140. package/src/translations.ts +0 -20
  141. package/src/types.ts +0 -211
  142. package/src/url.ts +0 -52
@@ -1,87 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Effect, Context } from 'effect';
6
-
7
- import { invariant } from '@dxos/invariant';
8
- import { log, LogLevel } from '@dxos/log';
9
-
10
- export type ComputeEvent =
11
- | {
12
- type: 'begin-compute';
13
- nodeId: string;
14
- inputs: Record<string, any>;
15
- }
16
- | {
17
- type: 'end-compute';
18
- nodeId: string;
19
- outputs: Record<string, any>;
20
- }
21
- | {
22
- type: 'compute-input';
23
- nodeId: string;
24
- property: string;
25
- value: any;
26
- }
27
- | {
28
- type: 'compute-output';
29
- nodeId: string;
30
- property: string;
31
- value: any;
32
- }
33
- | {
34
- type: 'custom';
35
- nodeId: string;
36
- event: any;
37
- };
38
-
39
- export class EventLogger extends Context.Tag('EventLogger')<
40
- EventLogger,
41
- { readonly log: (event: ComputeEvent) => void; readonly nodeId: string | undefined }
42
- >() {
43
- static noop: Context.Tag.Service<EventLogger> = {
44
- log: () => {},
45
- nodeId: undefined,
46
- };
47
- }
48
-
49
- export const logCustomEvent = (data: any) =>
50
- Effect.gen(function* () {
51
- const logger = yield* EventLogger;
52
- if (!logger.nodeId) {
53
- throw new Error('logCustomEvent must be called within a node compute function');
54
- }
55
- logger.log({
56
- type: 'custom',
57
- nodeId: logger.nodeId,
58
- event: data,
59
- });
60
- });
61
-
62
- export const createDefectLogger = <A, E, R>(): ((self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>) =>
63
- Effect.catchAll((error) =>
64
- Effect.gen(function* () {
65
- log.error('unhandled effect error', { error });
66
- throw error;
67
- }),
68
- );
69
-
70
- export const createEventLogger = (level: LogLevel, message: string = 'event'): Context.Tag.Service<EventLogger> => {
71
- const logFunction = (
72
- {
73
- [LogLevel.WARN]: log.warn,
74
- [LogLevel.VERBOSE]: log.verbose,
75
- [LogLevel.DEBUG]: log.debug,
76
- [LogLevel.INFO]: log.info,
77
- [LogLevel.ERROR]: log.error,
78
- } as any
79
- )[level];
80
- invariant(logFunction);
81
- return {
82
- log: (event: ComputeEvent) => {
83
- logFunction(message, event);
84
- },
85
- nodeId: undefined,
86
- };
87
- };
@@ -1,64 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Context } from 'effect';
6
-
7
- import type { SpaceId } from '@dxos/keys';
8
-
9
- /**
10
- * Allows calling into other functions.
11
- */
12
- export class FunctionCallService extends Context.Tag('FunctionCallService')<
13
- FunctionCallService,
14
- {
15
- callFunction(deployedFunctionId: string, input: any, spaceId?: SpaceId): Promise<any>;
16
- }
17
- >() {
18
- static fromClient(baseUrl: string, spaceId: SpaceId): Context.Tag.Service<FunctionCallService> {
19
- return {
20
- callFunction: async (deployedFunctionId: string, input: any) => {
21
- const url = getInvocationUrl(deployedFunctionId, baseUrl, { spaceId });
22
- const result = await fetch(url, {
23
- method: 'POST',
24
- headers: { 'Content-Type': 'application/json' },
25
- body: JSON.stringify(input),
26
- });
27
- if (result.status >= 300 || result.status < 200) {
28
- throw new Error('Failed to invoke function', { cause: new Error(`HTTP error: ${await result.text()}`) });
29
- }
30
- return await result.json();
31
- },
32
- };
33
- }
34
-
35
- static mock = () => {
36
- return {
37
- callFunction: async (deployedFunctionId: string, input: any) => {
38
- return input;
39
- },
40
- };
41
- };
42
- }
43
-
44
- // TODO(dmaretskyi): Reconcile with `getInvocationUrl` in `@dxos/functions/edge`.
45
- const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {
46
- const baseUrl = new URL('functions/', edgeUrl);
47
-
48
- // Leading slashes cause the URL to be treated as an absolute path.
49
- const relativeUrl = functionUrl.replace(/^\//, '');
50
- const url = new URL(`./${relativeUrl}`, baseUrl.toString());
51
- options.spaceId && url.searchParams.set('spaceId', options.spaceId);
52
- options.subjectId && url.searchParams.set('subjectId', options.subjectId);
53
- url.protocol = isSecure(url.protocol) ? 'https' : 'http';
54
- return url.toString();
55
- };
56
-
57
- const isSecure = (protocol: string) => {
58
- return protocol === 'https:' || protocol === 'wss:';
59
- };
60
-
61
- type InvocationOptions = {
62
- spaceId?: SpaceId;
63
- subjectId?: string;
64
- };
@@ -1,109 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Layer, type Context } from 'effect';
6
-
7
- import { AiService } from './ai';
8
- import { ConfiguredCredentialsService, CredentialsService } from './credentials';
9
- import { DatabaseService } from './database';
10
- import { EventLogger } from './event-logger';
11
- import { FunctionCallService } from './function-call-service';
12
- import { QueueService } from './queues';
13
- import { TracingService } from './tracing';
14
-
15
- /**
16
- * List of all service tags and their names.
17
- */
18
- export interface ServiceTagRecord {
19
- ai: AiService;
20
- credentials: CredentialsService;
21
- database: DatabaseService;
22
- eventLogger: EventLogger;
23
- functionCallService: FunctionCallService;
24
- tracing: TracingService;
25
- queues: QueueService;
26
- }
27
-
28
- /**
29
- * List of all services and their runtime types.
30
- */
31
- export type ServiceRecord = {
32
- [K in keyof ServiceTagRecord]: Context.Tag.Service<ServiceTagRecord[K]>;
33
- };
34
-
35
- /**
36
- * Union of all services.
37
- */
38
- export type Services = ServiceTagRecord[keyof ServiceTagRecord];
39
-
40
- const SERVICE_MAPPING: Record<string, keyof ServiceRecord> = {
41
- [AiService.key]: 'ai',
42
- [CredentialsService.key]: 'credentials',
43
- [DatabaseService.key]: 'database',
44
- [EventLogger.key]: 'eventLogger',
45
- [FunctionCallService.key]: 'functionCallService',
46
- [QueueService.key]: 'queues',
47
- [TracingService.key]: 'tracing',
48
- };
49
-
50
- export const SERVICE_TAGS: Context.Tag<any, any>[] = [
51
- AiService,
52
- CredentialsService,
53
- DatabaseService,
54
- EventLogger,
55
- FunctionCallService,
56
- TracingService,
57
- QueueService,
58
- ];
59
-
60
- const DEFAULT_SERVICES: Partial<ServiceRecord> = {
61
- tracing: TracingService.noop,
62
- };
63
-
64
- export class ServiceContainer {
65
- private _services: Partial<ServiceRecord> = { ...DEFAULT_SERVICES };
66
-
67
- /**
68
- * Set services.
69
- * @param services - Services to set.
70
- * @returns The container instance.
71
- */
72
- setServices(services: Partial<ServiceRecord>): this {
73
- this._services = { ...this._services, ...services };
74
- return this;
75
- }
76
-
77
- getService<T extends Context.Tag<any, any>>(tag: T): Context.Tag.Service<T> {
78
- const serviceKey = SERVICE_MAPPING[tag.key];
79
- const service = serviceKey != null ? this._services[serviceKey] : undefined;
80
- if (!service) {
81
- throw new Error(`Service not available: ${tag.key}`);
82
- }
83
- return service as Context.Tag.Service<T>;
84
- }
85
-
86
- clone(): ServiceContainer {
87
- return new ServiceContainer().setServices({ ...this._services });
88
- }
89
-
90
- // TODO(dmaretskyi): `getService` is designed to error at runtime if the service is not available, but layer forces us to provide all services and makes stubs for the ones that are not available.
91
- createLayer(): Layer.Layer<Services> {
92
- const ai = this._services.ai != null ? Layer.succeed(AiService, this._services.ai) : AiService.notAvailable;
93
- const credentials = Layer.succeed(CredentialsService, new ConfiguredCredentialsService());
94
- const database =
95
- this._services.database != null
96
- ? Layer.succeed(DatabaseService, this._services.database)
97
- : DatabaseService.notAvailable;
98
- const queues =
99
- this._services.queues != null ? Layer.succeed(QueueService, this._services.queues) : QueueService.notAvailable;
100
- const tracing = Layer.succeed(TracingService, this._services.tracing ?? TracingService.noop);
101
- const eventLogger = Layer.succeed(EventLogger, this._services.eventLogger ?? EventLogger.noop);
102
- const functionCallService = Layer.succeed(
103
- FunctionCallService,
104
- this._services.functionCallService ?? FunctionCallService.mock(),
105
- );
106
-
107
- return Layer.mergeAll(ai, credentials, database, queues, tracing, eventLogger, functionCallService);
108
- }
109
- }
@@ -1,16 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Effect, type Context } from 'effect';
6
-
7
- import { LogLevel } from '@dxos/log';
8
-
9
- import { type EventLogger, createEventLogger } from '../services';
10
-
11
- export const noopLogger: Context.Tag.Service<EventLogger> = {
12
- log: () => Effect.succeed(undefined),
13
- nodeId: undefined,
14
- };
15
-
16
- export const consoleLogger: Context.Tag.Service<EventLogger> = createEventLogger(LogLevel.INFO);
@@ -1,32 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type Context } from 'effect';
6
-
7
- import type { AiServiceClient } from '@dxos/ai';
8
- import type { QueueFactory } from '@dxos/echo-db';
9
-
10
- import { consoleLogger, noopLogger } from './logger';
11
- import { AiService, QueueService, ServiceContainer } from '../services';
12
- import type { EventLogger } from '../services/event-logger';
13
-
14
- export type TestServiceOptions = {
15
- ai?: AiServiceClient;
16
- queueFactory?: QueueFactory;
17
- enableLogging?: boolean;
18
- logger?: Context.Tag.Service<EventLogger>;
19
- };
20
-
21
- export const createTestServices = ({
22
- ai,
23
- queueFactory,
24
- enableLogging = false,
25
- logger = enableLogging ? consoleLogger : noopLogger,
26
- }: TestServiceOptions = {}): ServiceContainer => {
27
- return new ServiceContainer().setServices({
28
- ai: ai != null ? AiService.make(ai) : undefined,
29
- eventLogger: logger,
30
- queues: queueFactory != null ? QueueService.make(queueFactory, undefined) : undefined,
31
- });
32
- };
package/src/trace.ts DELETED
@@ -1,180 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { Type, type Ref } from '@dxos/echo';
8
- import { Queue } from '@dxos/echo-db';
9
- import { ObjectId } from '@dxos/echo-schema';
10
- import { log } from '@dxos/log';
11
-
12
- import { FunctionTrigger, type FunctionTriggerType } from './types';
13
-
14
- export enum InvocationOutcome {
15
- SUCCESS = 'success',
16
- FAILURE = 'failure',
17
- PENDING = 'pending',
18
- }
19
-
20
- // TODO(burdon): Convert to extensible discriminated union of EDGE events.
21
- export enum InvocationTraceEventType {
22
- START = 'start',
23
- END = 'end',
24
- }
25
-
26
- export const TraceEventException = Schema.Struct({
27
- timestampMs: Schema.Number,
28
- message: Schema.String,
29
- name: Schema.String,
30
- stack: Schema.optional(Schema.String),
31
- });
32
- export type TraceEventException = Schema.Schema.Type<typeof TraceEventException>;
33
-
34
- export const InvocationTraceStartEvent = Schema.Struct({
35
- /**
36
- * Queue message id.
37
- */
38
- id: ObjectId,
39
- type: Schema.Literal(InvocationTraceEventType.START),
40
- /**
41
- * Invocation id, the same for invocation start and end events.
42
- */
43
- invocationId: ObjectId,
44
- /**
45
- * Event generation time.
46
- */
47
- timestampMs: Schema.Number,
48
- /**
49
- * Data passed to function / workflow as an argument.
50
- */
51
- // TODO(burdon): Input schema?
52
- input: Schema.Object,
53
- /**
54
- * Queue for function/workflow invocation events.
55
- */
56
- invocationTraceQueue: Type.Ref(Queue),
57
- /**
58
- * DXN of the invoked function/workflow.
59
- */
60
- invocationTarget: Type.Ref(Type.Expando),
61
- /**
62
- * Present for automatic invocations.
63
- */
64
- trigger: Schema.optional(Type.Ref(FunctionTrigger)),
65
- }).pipe(Type.Obj({ typename: 'dxos.org/type/InvocationTraceStart', version: '0.1.0' }));
66
-
67
- export type InvocationTraceStartEvent = Schema.Schema.Type<typeof InvocationTraceStartEvent>;
68
-
69
- export const InvocationTraceEndEvent = Schema.Struct({
70
- /**
71
- * Trace event id.
72
- */
73
- id: ObjectId,
74
- type: Schema.Literal(InvocationTraceEventType.END),
75
- /**
76
- * Invocation id, will be the same for invocation start and end.
77
- */
78
- invocationId: ObjectId,
79
- /**
80
- * Event generation time.
81
- */
82
- // TODO(burdon): Remove ms suffix.
83
- timestampMs: Schema.Number,
84
- outcome: Schema.Enums(InvocationOutcome),
85
- exception: Schema.optional(TraceEventException),
86
- }).pipe(Type.Obj({ typename: 'dxos.org/type/InvocationTraceEnd', version: '0.1.0' }));
87
-
88
- export type InvocationTraceEndEvent = Schema.Schema.Type<typeof InvocationTraceEndEvent>;
89
-
90
- export type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;
91
-
92
- export const TraceEventLog = Schema.Struct({
93
- timestampMs: Schema.Number,
94
- level: Schema.String,
95
- message: Schema.String,
96
- context: Schema.optional(Schema.Object),
97
- });
98
-
99
- export const TraceEvent = Schema.Struct({
100
- id: ObjectId,
101
- // TODO(burdon): Need enum/numeric result (not string).
102
- outcome: Schema.String,
103
- truncated: Schema.Boolean,
104
- /**
105
- * Time when the event was persisted.
106
- */
107
- ingestionTimestampMs: Schema.Number,
108
- logs: Schema.Array(TraceEventLog),
109
- exceptions: Schema.Array(TraceEventException),
110
- }).pipe(Type.Obj({ typename: 'dxos.org/type/TraceEvent', version: '0.1.0' }));
111
-
112
- export type TraceEvent = Schema.Schema.Type<typeof TraceEvent>;
113
-
114
- /**
115
- * InvocationTrace event format.
116
- * This is the combined format of InvocationTraceStartEvent and InvocationTraceEndEvents for UI consumption.
117
- */
118
- export type InvocationSpan = {
119
- id: string;
120
- timestampMs: number;
121
- outcome: InvocationOutcome;
122
- input: object;
123
- durationMs: number;
124
- invocationTraceQueue: Ref.Ref<Queue>;
125
- invocationTarget: Ref.Ref<Type.Expando>;
126
- trigger?: Ref.Ref<FunctionTriggerType>;
127
- exception?: TraceEventException;
128
- };
129
-
130
- export const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {
131
- if (!items) {
132
- return [];
133
- }
134
-
135
- const eventsByInvocationId = new Map<string, { start?: InvocationTraceStartEvent; end?: InvocationTraceEndEvent }>();
136
- for (const event of items) {
137
- if (!('invocationId' in event)) {
138
- // Skip legacy format entries.
139
- continue;
140
- }
141
-
142
- const invocationId = event.invocationId;
143
- const entry = eventsByInvocationId.get(invocationId) || { start: undefined, end: undefined };
144
- if (event.type === InvocationTraceEventType.START) {
145
- entry.start = event as InvocationTraceStartEvent;
146
- } else if (event.type === InvocationTraceEventType.END) {
147
- entry.end = event as InvocationTraceEndEvent;
148
- }
149
-
150
- eventsByInvocationId.set(invocationId, entry);
151
- }
152
-
153
- const now = Date.now();
154
- const result: InvocationSpan[] = [];
155
-
156
- // Create spans for each invocation
157
- for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
158
- if (!start) {
159
- // No start event, can't create a meaningful span
160
- log.warn('found end event without matching start', { invocationId });
161
- continue;
162
- }
163
-
164
- const isInProgress = end === undefined;
165
-
166
- result.push({
167
- id: invocationId,
168
- timestampMs: start.timestampMs,
169
- durationMs: isInProgress ? now - start.timestampMs : end!.timestampMs - start.timestampMs,
170
- outcome: end?.outcome ?? InvocationOutcome.PENDING,
171
- exception: end?.exception,
172
- input: start.input,
173
- invocationTraceQueue: start.invocationTraceQueue,
174
- invocationTarget: start.invocationTarget,
175
- trigger: start.trigger,
176
- });
177
- }
178
-
179
- return result;
180
- };
@@ -1,20 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { Type } from '@dxos/echo';
6
-
7
- import { ScriptType } from './schema';
8
-
9
- export default [
10
- {
11
- 'en-US': {
12
- [Type.getTypename(ScriptType)]: {
13
- 'typename label': 'Script',
14
- 'typename label_zero': 'Scripts',
15
- 'typename label_one': 'Script',
16
- 'typename label_other': 'Scripts',
17
- },
18
- },
19
- },
20
- ];